/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
import cz.cvut.agents.rph.reversi.ReversiMove;
import cz.cvut.agents.rph.reversi.ReversiPlayer;
/**
*
* @author Martin Vajdl
*/
public class PlayerVajdlmic extends ReversiPlayer {
public int coordinateX;
public int coordinateY;
public int[][] board;
public int line = 0;
public int neighborX;
public int neighborY;
@Override
public String getName()
{
return "vajdlmic";
}
protected void startGame(int myColor, int opponentColor, int[][] playground)
{
this.width = board.length;
this.height = board[0].length;
}
@Override
public ReversiMove makeNextMove(int[][] board) {
int[][] CORNER = { { 0, 0 }, { 0, this.height - 1 }, { this.width - 1, 0 }, { this.width - 1, this.height - 1 } };
for (int i = 0; i < CORNER.length; i++)
{
this.coordinateX = CORNER[i][0];
this.coordinateY = CORNER[i][1];
if (correctMove(opponentColor, board) == true)
{
return new ReversiMove(this.coordinateX, this.coordinateY);
}
}
int[][] PROFITABLE = { { 2, 0 }, { this.width - 3, 0 }, { 0, 2 }, { this.width - 1, 2 }, { 0, this.height - 3 }, { this.width - 1, this.height - 3 }, { 2, this.height - 1 }, { this.width - 3, this.height - 1 } };
for (int i = 0; i < PROFITABLE.length; i++)
{
this.coordinateX = PROFITABLE[i][0];
this.coordinateY = PROFITABLE[i][1];
if (correctMove(opponentColor, board) == true)
{
return new ReversiMove(this.coordinateX, this.coordinateY);
}
}
if ((this.width > 4) && (this.height > 4)) {
int[][] MIDDLE = new int[(this.width - 4) * (this.width - 4)][(this.width - 4) * (this.width - 4)];
MIDDLE[0][0] = 2;
MIDDLE[0][1] = 2;
MIDDLE[((this.width - 4) * (this.width - 4) - 1)][0] = (this.width - 3);
MIDDLE[((this.width - 4) * (this.width - 4) - 1)][1] = (this.width - 3);
this.line = 0;
for (int i = 0; i < (this.width - 4) * (this.width - 4) - 1; i++) {
this.line += 1;
if (this.line == this.width - 3) {
MIDDLE[i][0] += 1;
MIDDLE[i][1] = 2;
this.line = 1;
}
MIDDLE[(i + 1)][0] = MIDDLE[i][0];
MIDDLE[(i + 1)][1] = (MIDDLE[i][1] + 1);
}
for (int i = 0; i < MIDDLE.length; i++)
{
this.coordinateX = MIDDLE[i][0];
this.coordinateY = MIDDLE[i][1];
if (correctMove(opponentColor, board) == true)
{
return new ReversiMove(this.coordinateX, this.coordinateY);
}
}
}
if (this.width > 6) {
int[][] BORDER = new int[(this.width - 6) * 4][(this.width - 6) * 4];
BORDER[0][0] = 3;
BORDER[0][1] = 0;
BORDER[((this.width - 6) * 2 - 1)][0] = (this.width - 4);
BORDER[((this.width - 6) * 2 - 1)][1] = (this.width - 1);
BORDER[((this.width - 6) * 2)][0] = 0;
BORDER[((this.width - 6) * 2)][1] = 3;
BORDER[((this.width - 6) * 4 - 1)][0] = (this.width - 1);
BORDER[((this.width - 6) * 4 - 1)][1] = (this.width - 4);
this.line = 0;
for (int i = 0; i < (this.width - 6) * 2 - 1; i++)
{
this.line += 1;
if (this.line == this.width - 5) {
BORDER[i][0] = 3;
BORDER[i][1] = (this.width - 1);
this.line = 1;
}
BORDER[(i + 1)][0] = (BORDER[i][0] + 1);
BORDER[(i + 1)][1] = BORDER[i][1];
}
this.line = 0;
for (int i = (this.width - 6) * 2; i < (this.width - 6) * 4 - 1; i++)
{
this.line += 1;
if (this.line == this.width - 5) {
BORDER[i][1] = 3;
BORDER[i][0] = (this.width - 1);
this.line = 1;
}
BORDER[(i + 1)][1] = (BORDER[i][1] + 1);
BORDER[(i + 1)][0] = BORDER[i][0];
}
for (int i = 0; i < BORDER.length; i++)
{
this.coordinateX = BORDER[i][0];
this.coordinateY = BORDER[i][1];
if (correctMove(opponentColor, board) == true)
{
return new ReversiMove(this.coordinateX, this.coordinateY);
}
}
}
if ((this.width > 4) && (this.height > 4))
{
int[][] NEXTBORDER = new int[(this.width - 4) * 4][(this.width - 4) * 4];
NEXTBORDER[0][0] = 2;
NEXTBORDER[0][1] = 1;
NEXTBORDER[((this.width - 4) * 2 - 1)][0] = (this.width - 3);
NEXTBORDER[((this.width - 4) * 2 - 1)][1] = (this.width - 2);
NEXTBORDER[((this.width - 4) * 2)][0] = 1;
NEXTBORDER[((this.width - 4) * 2)][1] = 2;
NEXTBORDER[((this.width - 4) * 4 - 1)][0] = (this.width - 2);
NEXTBORDER[((this.width - 4) * 4 - 1)][1] = (this.width - 3);
this.line = 0;
for (int i = 0; i < (this.width - 4) * 2 - 1; i++)
{
this.line += 1;
if (this.line == this.width - 3) {
NEXTBORDER[i][0] = 2;
NEXTBORDER[i][1] = (this.width - 2);
this.line = 1;
}
NEXTBORDER[(i + 1)][0] = (NEXTBORDER[i][0] + 1);
NEXTBORDER[(i + 1)][1] = NEXTBORDER[i][1];
}
this.line = 0;
for (int i = (this.width - 4) * 2; i < (this.width - 4) * 4 - 1; i++)
{
this.line += 1;
if (this.line == this.width - 3) {
NEXTBORDER[i][1] = 2;
NEXTBORDER[i][0] = (this.width - 2);
this.line = 1;
}
NEXTBORDER[(i + 1)][1] = (NEXTBORDER[i][1] + 1);
NEXTBORDER[(i + 1)][0] = NEXTBORDER[i][0];
}
for (int i = 0; i < NEXTBORDER.length; i++)
{
this.coordinateX = NEXTBORDER[i][0];
this.coordinateY = NEXTBORDER[i][1];
if (correctMove(opponentColor, board) == true)
{
return new ReversiMove(this.coordinateX, this.coordinateY);
}
}
}
int[][] NEXTCORNER = { { 0, 1 }, { 1, 0 }, { 0, this.height - 2 }, { this.width - 2, 0 }, { 1, this.height - 1 }, { this.width - 1, 1 }, { this.width - 2, this.height - 1 }, { this.width - 1, this.height - 2 } };
for (int i = 0; i < NEXTCORNER.length; i++)
{
this.coordinateX = NEXTCORNER[i][0];
this.coordinateY = NEXTCORNER[i][1];
{
return new ReversiMove(this.coordinateX, this.coordinateY);
}
}
int[][] BAD = { { 1, 1 }, { 1, this.height - 2 }, { this.width - 2, 1 }, { this.width - 2, this.height - 2 } };
for (int i = 0; i < BAD.length; i++)
{
this.coordinateX = BAD[i][0];
this.coordinateY = BAD[i][1];
if (correctMove(opponentColor, board) == true)
{
return new ReversiMove(this.coordinateX, this.coordinateY);
}
}
return new ReversiMove(this.coordinateX, this.coordinateY);
}
private boolean correctMove(int opponentColor, int[][] board)
{
if (board[this.coordinateX][this.coordinateY] != -1) {
return false;
}
int[][] neighbori = { { -1, -1 }, { 0, -1 }, { 1, -1 }, { -1, 0 }, { 1, 0 }, { -1, 1 }, { 0, 1 }, { 1, 1 } };
for (int[] neighbor : neighbori)
{
this.neighborX = (this.coordinateX + neighbor[0]);
this.neighborY = (this.coordinateY + neighbor[1]);
if (onBoard(this.neighborX, this.neighborY, board))
{
if (board[this.neighborX][this.neighborY] == opponentColor)
{
if (tryCorrect(neighbor, board))
{
return true;
}
}
}
}
return false;
}
private boolean tryCorrect(int[] neighbor, int[][] board) {
int newX = this.coordinateX + neighbor[0];
int newY = this.coordinateY + neighbor[1];
do
{
newX += neighbor[0];
newY += neighbor[1];
if (!onBoard(newX, newY, board)) {
return false;
}
if (board[newX][newY] == -1) {
return false;
}
}
while (board[newX][newY] != this.myColor);
return true;
}
private boolean onBoard(int x, int y, int[][] board)
{
if ((x < 0) || (x >= board.length)) {
return false;
}
if ((y < 0) || (y >= board[0].length)) {
return false;
}
return true;
}
}