id stringlengths 36 36 | text stringlengths 1 1.25M |
|---|---|
a799e129-0cba-41ea-bf6b-13c82201acd0 | public Tetromino(Type type) {
this.type = type;
this.rotation = Rotation.values()[0];
this.point = new TetrisPoint(4, 0);
this.blocks = TETROMINO[this.type.getValue() - 1][this.rotation.getValue()];
this.lock = 0;
} |
a7a8f8b9-9367-41c5-baa2-abe257097f59 | public Tetromino(Type type, TetrisPoint point) {
this.type = type;
this.rotation = Rotation.values()[0];
this.point = point;
this.blocks = TETROMINO[this.type.getValue() - 1][this.rotation.getValue()];
this.lock = 0;
} |
f0908c5f-a3e6-43fd-b6f1-ce8d149ef6cd | public Tetromino(Type type, Rotation rotation) {
this.type = type;
this.rotation = rotation;
this.point = new TetrisPoint(4, 0);
this.blocks = TETROMINO[this.type.getValue() - 1][this.rotation.getValue()];
this.lock = 0;
} |
76e65698-a0ee-4785-a437-82dce56ee5a1 | public TetrisPoint[] getBlocks() {
return this.blocks;
} |
3b71edc4-62ae-46ca-94d7-5e4aeac8b5f3 | public Type getType() {
return this.type;
} |
aa8d249c-1966-47e6-9679-8a599c66ba19 | public Rotation getRotation() {
return this.rotation;
} |
6120f96c-7225-4083-8c51-f001598a4b6f | public TetrisPoint getPoint() {
return this.point;
} |
ea45ad09-c3ee-4860-b8b6-3a5bc11b681f | public void setPoint(TetrisPoint point) {
this.point = point;
} |
de9acb22-e522-4cc9-8ea4-1cee74bf564e | public boolean isLocked() {
return this.lock >= LOCKING_THRESHOLD;
} |
33d31424-f8f5-4717-8b86-bb38f6b10fc3 | public boolean isLocking() {
return this.lock > 0;
} |
a6da393b-f671-4fcd-808b-a9de05a3ca61 | public int getLock() {
return this.lock;
} |
6a5ab06c-4011-4f80-80ab-d7a527773912 | public boolean inBounds() {
for (TetrisPoint mino : this.blocks) {
if (!TetrisBoard.inBounds(mino.add(point))) return false;
}
return true;
} |
cce6b929-d7a7-4eba-80cc-82708a14bda8 | public boolean inTetromino(TetrisPoint point) {
for (TetrisPoint mino : this.blocks) {
if (mino.add(this.point).equals(point)) return true;
}
return false;
} |
7a3bece2-23ea-42dc-944e-3342b3f6ca16 | public boolean intersects(Tetromino tetromino) {
for (TetrisPoint a : this.blocks) {
for (TetrisPoint b : tetromino.getBlocks()) {
if (a.add(this.point).equals(b.add(tetromino.getPoint()))) return true;
}
}
return false;
} |
c021038b-f442-4dd2-8eaa-73cb2922f0e1 | public boolean inFreeSpace(TetrisBoard board) {
for (TetrisPoint mino : this.blocks) {
if (board.get(mino.add(point)) != Tetromino.Type.X) return false;
}
return true;
} |
4e77a68c-dbbc-42bf-a8d2-462ede49e128 | public boolean validPlacement(TetrisBoard board) {
return this.inBounds() && this.inFreeSpace(board);
} |
223d81bb-8d9d-4d17-b20d-960bcf21b77a | public boolean blockedBelow(TetrisBoard board) {
for (TetrisPoint a : this.blocks) {
boolean bottom_block = true;
for (TetrisPoint b : this.blocks) {
if (b.equals(new TetrisPoint(a.getX(), a.getY() + 1))) bottom_block = false;
}
if (bottom_block) {
TetrisPoint tmp = this.poi... |
92c42970-e6da-4ea0-aadf-8f85321e29c8 | public boolean addTo(TetrisBoard board) {
if (!this.validPlacement(board)) return false;
for (TetrisPoint mino : this.blocks) board.set(mino.add(point), type);
return true;
} |
bee5d3e2-39a4-4d0b-9a67-4e8653134a15 | public boolean removeFrom(TetrisBoard board) {
for (TetrisPoint mino : this.blocks) board.set(mino.add(point), Type.X);
return true;
} |
afcdf7ca-9ab5-4390-b1b9-a5a0ffa7031f | public boolean move(TetrisBoard board, TetrisPoint point) {
//this.removeFrom(board);
TetrisPoint tmp = this.point;
this.point = point;
if (!this.validPlacement(board)) {
this.point = tmp;
//this.addTo(board);
return false;
}
this.lock = 0;
//this.addTo(board);
return t... |
5bbd70cb-3675-4ae8-b869-a86a4cf1e52a | public boolean shift(TetrisBoard board, TetrisPoint displacement) {
return this.move(board, this.point.add(displacement));
} |
1972089f-51fd-43e1-9d56-61b24b86a9ae | public void drop(TetrisBoard board) {
this.lock = !this.shift(board, new TetrisPoint(0, 1)) ? this.lock + 1: 0;
} |
ba24a68b-bf91-495b-a327-b576862fa1ad | public void hardDrop(TetrisBoard board) {
for (; !this.isLocked(); this.drop(board));
} |
d89bc9b6-3e7a-4eac-bbcb-f64d255f7522 | public boolean setRotation(TetrisBoard board, Rotation rotation) {
return this.setRotation(board, rotation, true);
} |
e9205e88-bbd5-4f22-bce4-485ceccb2903 | public boolean setRotation(TetrisBoard board, Rotation rotation, boolean wall_kick) {
Rotation tmp = this.rotation;
TetrisPoint[] tmp2 = this.blocks;
this.rotation = rotation;
this.blocks = TETROMINO[this.type.getValue() - 1][this.rotation.getValue()];
if (!this.validPlacement(board)) {
/* Res... |
4abc6e6f-803c-4d18-8f47-d4a41aa159fb | public boolean rotateCounterClockwise(TetrisBoard board) {
return this.setRotation(board, Rotation.values()[(this.rotation.getValue() + 1) % ROTATIONS]);
} |
e0b3da93-a9d1-4bec-ac76-bc65e7aae7ef | public boolean rotateClockwise(TetrisBoard board) {
// -1 == (n - 1) mod n
return this.setRotation(board, Rotation.values()[((this.rotation.getValue() + (ROTATIONS - 1)) % ROTATIONS)]);
} |
d7b70929-911c-45ee-98e2-2dad8ee58c77 | public String toString() {
String out = "tetris.Tetromino[";
out += "Type: " + this.type + ", ";
out += "Rotation: " + this.rotation + ", ";
for (TetrisPoint mino : this.blocks) {
//TetrisPoint tmp = mino.add(point);
out += "(" + mino.getX() + ", " + mino.getY() + "), ";
}
return out... |
701a9b72-b0ae-4ccb-a83e-d54886224cde | public Tetris() {
rng = new TetrominoRandom();
board = new TetrisBoard();
running = true;
game_over = false;
this.timer = null;
firstFrame = true;
lines = 0;
locked = false;
dropCounter = 1;
lastClearedCounter = 1;
level = 1;
hold = null;
score = 0;
} |
2324d77f-b7c0-48cb-9103-cd609efe9b23 | public static void main(String[] args) {
final Tetris game = new Tetris();
final TetrisFrame frame = game.createMainWindow();
final ActionListener ticker = new ActionListener() {
public void actionPerformed(ActionEvent event) {
game.tick(frame);
}
};
final Timer timer = new Tim... |
44f9e519-eb50-471b-811a-6edf4d6f03cc | public void actionPerformed(ActionEvent event) {
game.tick(frame);
} |
106fe9f1-c8dc-43cd-83cb-90835f550ab3 | public void run() {
timer.start();
} |
f876c002-a794-47b9-8cd0-ce5ccb42661d | private void setTimer(Timer timer) {
this.timer = timer;
} |
b334fc4c-638a-4d67-90f7-737323f7e388 | private TetrisFrame createMainWindow() {
JPanel mainPanel = new JPanel();
mainPanel.setLayout(new BoxLayout(mainPanel, BoxLayout.X_AXIS));
JPanel sidePanel = new JPanel();
sidePanel.setLayout(new BoxLayout(sidePanel, BoxLayout.Y_AXIS));
mainPanel.add(new TetrisPanel(this));
sidePanel.add(this... |
0d74d2cd-6cf0-4502-8d8a-1fa684b842e1 | public TetrisBoard getBoard() {
return board;
} |
b2b81643-cb01-446d-8e86-f187300d4d43 | public int getLines() {
return lines;
} |
9461edaf-dbda-4d75-81be-5c0b49b17830 | public Tetromino getActiveTetromino() {
return activeTetromino;
} |
a49d68c2-dc0d-4bd2-9058-77fa74c3dd96 | public double getFramerate() {
return framerate;
} |
7fe32001-b55a-4d31-ae2a-8faee3fb4855 | public boolean isGameOver() {
return this.game_over;
} |
fd5c676c-cd51-40e3-9db3-491000a2ae6a | public boolean isRunning() {
return this.running;
} |
6798874e-1a5b-44a2-8b0d-ca03d52a50dc | public void toggleRunning() {
this.running = !this.running;
} |
f2cda100-920e-4093-b85d-45162afd4f9e | public boolean activateNextTetromino() {
activeTetromino = new Tetromino(this.rng.get());
return activeTetromino.inFreeSpace(this.board);
} |
61aff825-db5c-4c75-b3e8-bc8bff9ae70f | public TetrominoRandom getRNG() {
return rng;
} |
0245250a-d947-482d-8712-80dd0cf08b5e | public boolean holdingPiece() {
return this.hold != null;
} |
3834f894-d5e2-4d62-a1f0-44ffeb1c0942 | public Tetromino.Type getHoldPiece() {
return this.hold;
} |
dc40be1b-3ee9-49c7-b88a-2164b28279fd | public void holdPieceAction() {
//this.activeTetromino.removeFrom(this.board);
Tetromino.Type tmp = this.activeTetromino.getType();
this.activeTetromino = this.hold == null ? new Tetromino(this.rng.get()): new Tetromino(this.hold);
this.hold = tmp;
//this.activeTetromino.addTo(this.board);
} |
6c33c676-be7d-41ad-b1ef-41c150603cc9 | public void tick(JFrame frame) {
if (game_over) {
board.resetBoard();
this.timer.stop();
activeTetromino = null;
frame.repaint();
return;
}
if (this.running) {
if (firstFrame) {
lastTime = System.nanoTime();
frameAverageCounter = 1;
firstFrame = f... |
7abd41e8-c1c2-416e-aeff-1e8da4bea7b8 | public Customer(EmiratesId emiratesId, DriversLicense driversLicense,
Passport passport, EyeTest eyeTest,
DriversLicenseTranslation driversLicenseTranslation) {
this.emiratesId = emiratesId;
this.driversLicense = driversLicense;
this.passport = passport;
... |
0c1790c2-3525-4d92-8e23-538cfbff3072 | @Override
public String toString() {
if (passport != null) {
return (passport.firstName + " " + passport.lastName);
} else {
return "<customer with no passport>";
}
} |
7680ef18-d28b-4f89-bdd8-1ee28d331018 | public EyeTester(SynchronizedQueue<Customer> eyeTestingQueue,
SynchronizedQueue<Customer> translatingQueue,
SynchronizedQueue<Customer> licensingQueue,
SynchronizedQueue<UAEDriversLicense> successQueue,
SynchronizedQueue<Customer> failureQueue,
int numCustomer... |
575aff51-9e1f-4193-9fca-f93a1fd1b664 | public boolean documentsCorrect(Customer customer) {
if(customer.emiratesId == null ||
customer.driversLicense == null ||
customer.passport == null) {
return false;
} else {
return true;
}
} |
d869fddb-5f87-485e-873f-1cf04e6696d4 | public void eyeTest(Customer customer) {
String eyeTestNumber = UUID.randomUUID().toString();
customer.eyeTest = new EyeTest(customer.emiratesId.firstName,
customer.emiratesId.lastName,
customer.emiratesId.nationality,
customer.emiratesId.gender,
... |
71f9fd26-999d-40a7-9566-bdb4ed76e9e0 | public void run() {
while ((failureQueue.size() + successQueue.size()) != numCustomers) {
Customer customer = eyeTestingQueue.poll();
if (customer != null) {
System.out.println("\t\tCustomer processed by eye tester: " + customer);
if (!documentsCorrect(customer)) {
... |
6ed9f189-2984-49fc-b03e-470e5e68fa22 | public int getMinWait() {
return minWait;
} |
b8c1f542-987e-477f-835c-4ac5af2c3b75 | public int getMaxWait() {
return maxWait;
} |
ca087a99-826d-47c2-a6be-73a5d3482ec8 | public UAEDriversLicense(Customer driver) {
this.driver = driver;
} |
7d3a1238-e9af-420b-be20-38db150cb86a | public Licensor(SynchronizedQueue<Customer> licensingQueue,
SynchronizedQueue<Customer> eyeTestingQueue,
SynchronizedQueue<Customer> translatingQueue,
SynchronizedQueue<Customer> printingQueue,
SynchronizedQueue<UAEDriversLicense> successQueue,
SynchronizedQue... |
20aa2c87-7aef-40eb-a565-79d71e72fe36 | public boolean documentsCorrect(Customer customer) {
if(customer.emiratesId == null ||
customer.driversLicense == null ||
customer.passport == null) {
return false;
} else {
return true;
}
} |
852c2efb-71e1-4b5d-954e-48ae776d0bdb | public void run() {
while ((failureQueue.size() + successQueue.size()) != numCustomers) {
Customer customer = licensingQueue.poll();
if (customer != null) {
System.out.println("\t\t\t\tCustomer processed by licensor: " + customer);
if (!documentsCorrect(customer)) {
failur... |
63eed5a4-713e-4b62-8a58-fdc3ef554b6b | public int getMinWait() {
return minWait;
} |
4adb8025-e26d-4ad5-9d3b-850b74c99158 | public int getMaxWait() {
return maxWait;
} |
ca236f4e-a339-43f8-9385-cf1d1f440562 | public EmiratesId(String firstName, String lastName, String nationality,
char gender, Date dateOfBirth, Date expiryDate, String idNumber) {
super(firstName, lastName, nationality, gender, dateOfBirth, expiryDate);
this.idNumber = idNumber;
} |
e9d133cb-d78e-4c91-a838-294105c0af56 | public Passport(String firstName, String lastName, String nationality,
char gender, Date dateOfBirth, Date expiryDate) {
super(firstName,lastName,nationality,gender,dateOfBirth,expiryDate);
} |
093609ff-6e16-42fd-bfa4-eea5f448de31 | public SynchronizedQueue() {
super();
agents = new LinkedList<AbstractAgent>();
} |
504439d8-8b1f-4ce8-8591-850b70b5c365 | public synchronized void registerAgent(AbstractAgent agent) {
agents.push(agent);
} |
de82868f-b13d-4b16-8d10-0ae447007f24 | public synchronized void deregisterAgent(AbstractAgent agent) {
agents.remove(agent);
} |
bc7bade5-d3e8-4049-8e58-7f6648be4e08 | @Override
public synchronized boolean add(E object) {
return super.add(object);
} |
4c3012db-caf6-4e78-88a2-2407a51d77c0 | @Override
public synchronized E poll() {
if (this.size() == 0) return null;
return super.poll();
} |
e6bc3050-7bd1-4fe5-ad54-6523505b017c | public double peekTime() {
// Naive algorithm that estimates the waiting time by doing the agent count over the sum of the wait times
// for each of the agents (to get the customers / second rate) multiplied by the number of people in the queue
int waitSum = 0;
Iterator<AbstractAgent> ... |
41583b70-d7e5-437f-880d-cb6aca5814e9 | public PrintingAgent(CountDownLatch latch,
SynchronizedQueue printingQueue,
SynchronizedQueue successQueue,
SynchronizedQueue failureQueue,
int numCustomers) {
this.latch = latch;
this.failureQueue = failureQueue;
this.successQueue = successQueue;
this.numCu... |
a9d3eaad-2b07-4b8a-ba5f-6a7b23856a03 | private synchronized void signalResults() {
if (!isFinished) {
isFinished = true;
System.out.println("TOTAL STATS: "+
failureQueue.size()+" failures, "+
successQueue.size()+" successes "+
"("+numCustomers+" total)");
}
... |
a84215de-d3f1-4d12-9dcb-8ffdc670c45a | public boolean documentsCorrect(Customer customer) {
if(customer.emiratesId == null ||
customer.driversLicense == null ||
customer.passport == null) {
return false;
} else {
return true;
}
} |
bfd33424-aee4-4f51-9852-f77db2a20a71 | public void run() {
while((failureQueue.size()+successQueue.size()) != numCustomers) {
while (!printer.isIdle()) {
try {
// wait for 10 seconds
Thread.sleep(10000);
} catch (InterruptedException ex) {
}
}
... |
68fd2d8a-4730-4529-9350-a2eee8f1fb5b | public AbstractPrimaryDocument(String firstName, String lastName,
String nationality, char gender,
Date dateOfBirth, Date expiryDate) {
this.firstName = firstName;
this.lastName = lastName;
this.nationality = nationality;
... |
5880c4c3-a6fb-4f64-95b7-c08014e6852b | public DriversLicenseTranslation(DriversLicense driversLicense) {
this.driversLicense = driversLicense;
} |
96cd7e31-4cf5-4640-bb32-394aafd26e25 | AbstractAgent() {
} |
90d57c16-ad49-4bd4-ac38-6d84e2ad5c1b | public abstract void run(); |
fd5ebfbb-661b-4c16-8e70-0c0743698863 | public Customer pull(SynchronizedQueue<Customer> queue) {
Customer customer = queue.remove();
return customer;
} |
32f52a7c-418c-4e22-9f8c-67dd3290209d | public void push(SynchronizedQueue<Customer> queue, Customer customer) {
queue.add(customer);
} |
1612202b-f51b-4278-b3b0-da286736f93f | public int getAverageWait() {
return (getMinWait() + getMaxWait()) / 2;
} |
dfd99041-b998-4df5-be34-a08e6add9063 | protected void process() {
try {
Thread.sleep(getMinWait() + (int) (Math.random() * (getMaxWait()-getMinWait())));
} catch (InterruptedException ex) {
// ignore
}
} |
136b6c51-0aa4-4c17-9733-a435df43d263 | abstract int getMinWait(); |
d61638d5-0d3c-4994-a45b-c142cd513f28 | abstract int getMaxWait(); |
4cc392f0-39ef-4148-81cb-2ebd0b76297c | Printer(SynchronizedQueue<UAEDriversLicense> successQueue,
SynchronizedQueue<Customer> failureQueue,
int numCustomers) {
this.successQueue = successQueue;
this.failureQueue = failureQueue;
this.numCustomers = numCustomers;
} |
64211299-d172-4e42-b717-a64b4c437d16 | public boolean isIdle() {
return isIdle;
} |
31c8aec8-9e6e-48a1-a5a5-3edae1c70d68 | public void turnOff() {
isOn = false;
} |
ee5a613f-4a97-45bf-a885-a148a4c3353a | public void print(Customer customer) {
isIdle = false;
activeJob = customer;
} |
ea3544a5-d0e4-48c3-971c-34072d0dd309 | private void printLicense() {
UAEDriversLicense dl = new UAEDriversLicense(activeJob);
System.out.println("\t\t\t\t\t\tPrinting: "+activeJob);
try {
Thread.sleep(300000);
} catch (InterruptedException ex) {
// ignore
}
successQueue.add(dl);
... |
f12e2ca4-b081-42c9-a6bc-70c719aedb6c | public void run() {
while (isOn) {
if (!isIdle) {
printLicense();
}
// wait 10 seconds before polling to avoid busy-waiting
try {
Thread.sleep(10000);
} catch (InterruptedException ex) {
// ignore
... |
75f6914b-de45-4038-8201-63c472dfd641 | public Translator(SynchronizedQueue<Customer> translatingQueue,
SynchronizedQueue<Customer> eyeTestingQueue,
SynchronizedQueue<Customer> licensingQueue,
SynchronizedQueue<UAEDriversLicense> successQueue,
SynchronizedQueue<Customer> failureQueue,
int numCustome... |
74f44b24-5073-40e2-b23f-29f48624f9ca | public boolean documentsCorrect(Customer customer) {
if(customer.emiratesId == null ||
customer.driversLicense == null ||
customer.passport == null) {
return false;
} else {
return true;
}
} |
5df59fe8-56ed-4ddf-bb7f-92b052616ad1 | public void translate(Customer customer) {
customer.driversLicenseTranslation = new DriversLicenseTranslation(customer.driversLicense);
} |
ab75f4e1-cf97-4008-8321-c627993ca786 | public void run() {
while ((failureQueue.size() + successQueue.size()) != numCustomers) {
Customer customer = translatingQueue.poll();
if (customer != null) {
System.out.println("\t\t\tCustomer processed by translator: " + customer);
if (!documentsCorrect(customer)) {
failureQueue.ad... |
93cc9ce1-8b60-4761-a23f-95bfe519b9e9 | public int getMinWait() {
return minWait;
} |
a62d5e94-4048-4ecd-b1d5-d347aac17088 | public int getMaxWait() {
return maxWait;
} |
e18c0f38-812e-458d-b8c6-a107346df2bc | public EyeTest(String firstName, String lastName, String nationality,
char gender, Date dateOfBirth, Date expiryDate,
String emiratesIdNumber) {
// Java date libraries suck; this is imprecise
super(firstName,lastName,nationality,gender,dateOfBirth,
exp... |
8564678a-a1fd-4665-9ea9-449d81db8e8d | public static void main(String args[]) {
run(makeCustomerVector(10));
} |
1a3296c3-0836-4627-b81a-4d91a7505a86 | public static Vector<UAEDriversLicense> run(Vector<Object[]> customerObjectVector) {
numCustomers = customerObjectVector.size();
(new Thread(new Receptionist(
// Options for strategy are 'RANDOM' for random placement, 'PEEK' for picking the queue with the lowest time by
... |
94e9a1a9-e137-407a-8690-19bf2a364a23 | private static void initializeCustomers(
Vector<Object[]> customerObjectVector,
SynchronizedQueue<Customer> customerQueue) {
long sleepSoFar = 0;
while (!customerObjectVector.isEmpty()) {
Object[] currentObject = customerObjectVector.remove(0);
long sleep... |
2ab96f82-6817-44d2-b93e-00731645a20b | private static Vector<UAEDriversLicense> convertToVector(
SynchronizedQueue<UAEDriversLicense> successQueue) {
Vector<UAEDriversLicense> successVector = new Vector<UAEDriversLicense>();
while (!successQueue.isEmpty()) {
successVector.add(successQueue.poll());
}
re... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.