package edu.ics.game.server;

public class TicTacToe extends Game {
	public TicTacToe() {
		super(3, 3);
	}

	public void play(int... args) {
		if (args.length >= 2) {
			int x = args[0];
			int y = args[1];
			if (this.isEmpty(x, y)) {
				this.board[y][x] = this.currentPlayer;
				if (this.threeInARow(x, y)) {
					this.winner = this.currentPlayer;
					this.ended = true;
				} else if (this.isFull()) {
					this.ended = true;
				} else {
					this.next();
				}
			}
		}
	}

	private boolean threeInARow(int x, int y) {		
		int[] arr = {0, 1};
		for (int _x : arr) {
			for (int _y: arr) {
				if (_x == 0 && _y == 0) {
					continue;
				}

				int count = 0;
				for (int i = x - 2 * _x, j = y - 2 * _y; i <= x + 2 * _x && j <= y + 2 * _y; i += _x, j += _y) {
					if (this.isInBounds(i, j) && this.board[j][i] == this.currentPlayer) {
						count++;
						if (count == 3) {
							return true;
						}
					}
				} 
			}
		}
		return false;
	}

	private boolean isFull() {
		for (int y = 0; y < this.height; y++) {
			for (int x = 0; x < this.width; x++) {
				if (this.board[y][x] == -1) {
					return false;
				}
			}
		}
		return true;
	}
}

@@ -534,57 +534,62 @@
 nt%5B%5D
+%5B%5D
  arr = 
+%7B
 %7B0, 1%7D
-;%0A%09%09for (int _x : arr) %7B
+, %7B1, 0%7D, %7B1, 1%7D, %7B-1, 1%7D%7D;
 %0A%09%09
-%09
 for (int
  _y:
@@ -588,73 +588,85 @@
 (int
- _y: arr) %7B%0A%09%09%09%09if (_x == 0 && _y == 0) %7B%0A%09%09%09%09%09continue;%0A%09%09%09%09%7D%0A%0A%09
+%5B%5D directions : arr) %7B%0A%09%09%09int _x = directions%5B0%5D;%0A%09%09%09int _y = directions%5B1%5D;%0A
 %09%09%09i
@@ -679,17 +679,16 @@
 nt = 0;%0A
-%09
 %09%09%09for (
@@ -722,16 +722,44 @@
  2 * _y;
+ (_x %3C 0 ? i %3E= x + 2 * _x :
  i %3C= x 
@@ -766,19 +766,49 @@
 + 2 * _x
+ )
  &&
+ (_y %3C 0 ? j %3E= y + 2 * _y :
  j %3C= y 
@@ -815,16 +815,17 @@
 + 2 * _y
+)
 ; i += _
@@ -834,25 +834,24 @@
  j += _y) %7B%0A
-%09
 %09%09%09%09if (this
@@ -918,17 +918,16 @@
  %7B%0A%09%09%09%09%09
-%09
 count++;
@@ -927,17 +927,16 @@
 ount++;%0A
-%09
 %09%09%09%09%09if 
@@ -952,25 +952,24 @@
  3) %7B%0A%09%09%09%09%09%09
-%09
 return true;
@@ -973,29 +973,20 @@
 ue;%0A
-%09%09%09%09%09%09%7D%0A
 %09%09%09%09%09%7D%0A
+
 %09%09%09%09%7D
- 
 %0A%09%09%09

Add a missing direction