-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathProtocol.java
More file actions
33 lines (29 loc) · 793 Bytes
/
Copy pathProtocol.java
File metadata and controls
33 lines (29 loc) · 793 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
/* Protocol:
* OOOOXXYY
*
* O: Opcode
* 0 = client to server to set field
* 1 = server to client to set "X"
* 2 = server to client to set "O"
* 3 = server to client to indicate win
* 4 = server to client to indicate loss
* 5 = server to client to indicate tie
* 6 = server to client to indicate new round
* 7 = server to client to indicate failure
* X: X coord
* Y: Y coord
*/
public class Protocol {
public static final int SET = 0, SETX = 1, SETO = 2, WIN = 3, LOSS = 4,
TIE = 5, NEWROUND = 6, FAIL = 7;
public static final int DEFAULTPORT = 31137;
public static int opcode(int input) {
return (input & 0xF0) >> 4;
}
public static int x(int input) {
return (input & 0xC) >> 2;
}
public static int y(int input) {
return input & 3;
}
}