public AIBoard(Board board) { supBoard = board; rows = 9; spaces = new PLAYER_COLOR[9][]; spaces[0] = new PLAYER_COLOR[5]; spaces[1] = new PLAYER_COLOR[6]; spaces[2] = new PLAYER_COLOR[7]; spaces[3] = new PLAYER_COLOR[8]; spaces[4] = new PLAYER_COLOR[9]; spaces[5] = new PLAYER_COLOR[8]; spaces[6] = new PLAYER_COLOR[7]; spaces[7] = new PLAYER_COLOR[6]; spaces[8] = new PLAYER_COLOR[5]; evaluationMatrix = new byte[9][]; evaluationMatrix[0] = new byte[] { 0, 0, 0, 0, 0 }; evaluationMatrix[1] = new byte[] { 0, 1, 1, 1, 1, 0 }; evaluationMatrix[2] = new byte[] { 0, 1, 3, 3, 3, 1, 0 }; evaluationMatrix[3] = new byte[] { 0, 1, 3, 5, 5, 3, 1, 0 }; evaluationMatrix[4] = new byte[] { 0, 1, 3, 5, 7, 5, 3, 1, 0 }; evaluationMatrix[5] = new byte[] { 0, 1, 3, 5, 5, 3, 1, 0 }; evaluationMatrix[6] = new byte[] { 0, 1, 3, 3, 3, 1, 0 }; evaluationMatrix[7] = new byte[] { 0, 1, 1, 1, 1, 0 }; evaluationMatrix[8] = new byte[] { 0, 0, 0, 0, 0 }; }
public void Move(List <MoveMarble> moves, PLAYER_COLOR player) //modificar todo el cuerpo { foreach (MoveMarble move in moves) { bool white = move.CurrentCell.Marble.isWhite; for (byte row = 0; row < rows; row++) { int maxcolumn = spaces[row].Length; for (byte column = 0; column < maxcolumn; column++) { if (move.CurrentCell.Row == row && move.CurrentCell.Column == column && move.hasToDestroy) { spaces[row][column] = PLAYER_COLOR.NONE; } else if (move.CurrentCell.Row == row && move.CurrentCell.Column == column && spaces[row][column] != PLAYER_COLOR.NONE) { spaces[row][column] = PLAYER_COLOR.NONE; } else if (move.NextCell != null && move.NextCell.Row == row && move.NextCell.Column == column && spaces[row][column] == PLAYER_COLOR.NONE) { if (white) { spaces[row][column] = PLAYER_COLOR.WHITE; } else { spaces[row][column] = PLAYER_COLOR.BLACK; } } } } } }
public keyposition(int _row, int _column, PLAYER_COLOR _changedTo, Direction _direction) { row = _row; column = _column; changedTo = _changedTo; direction = _direction; }
public bool IsWinningPosition(PLAYER_COLOR player) { int numberMarbles = 0; for (byte row = 0; row < rows; row++) { int maxcolumn = spaces[row].Length; for (byte column = 0; column < maxcolumn; column++) { if (spaces[row][column] == Opponent(player)) { numberMarbles++; } } } if (numberMarbles <= 8) { return(true); } else { return(false); } }
PLAYER_COLOR Opponent(PLAYER_COLOR player) { if (player == PLAYER_COLOR.WHITE) { return(PLAYER_COLOR.BLACK); } else { return(PLAYER_COLOR.WHITE); } }
public int Evaluate(PLAYER_COLOR player) { if (IsWinningPosition(player)) { return(100000); } if (IsWinningPosition(Opponent(player))) { return(-100000); } int evaluationSum = 0; int numberMarblesOpponents = 0; int numberMarblesPlayer = 0; // canicas del AI en el medio for (byte row = 0; row < rows; row++) { int maxcolumn = spaces[row].Length; for (byte column = 0; column < maxcolumn; column++) { if (spaces [row] [column] == player) { evaluationSum += evaluationMatrix [row] [column]; numberMarblesPlayer++; } else if (spaces[row][column] == Opponent(player)) { evaluationSum -= evaluationMatrix[row][column] * 5; numberMarblesOpponents++; } if (isHexagon(row, column)) { evaluationSum += 1; } } } evaluationSum += (14 - numberMarblesOpponents) * 100; evaluationSum -= (14 - numberMarblesPlayer) * 3; // Número de canicas amigas y enemigas // Cuento las canicas de los enemigos y resto del numero total posible // Si cuanto menos enemigos más puntos se puede condierar como haber atacado? return(evaluationSum); }
public void Play(PLAYER_COLOR player) { this.activePlayer = player; ObserveBoard(); ScoringMove move; System.DateTime a = System.DateTime.Now; move = MTD(board); System.DateTime b = System.DateTime.Now; Debug.Log("tiempo del posible moves" + (b - a)); Debug.Log("Jugador Activo: " + activePlayer + " Jugada Elegida: " + move.move.Count + "/ " + move.score); Move(move); }
private List <PLAYER_COLOR> selectMarbles(int row, int column, int numMarbles, PLAYER_COLOR player, Direction direction) { List <PLAYER_COLOR> selectedMarbles = new List <PLAYER_COLOR>(); PLAYER_COLOR actualMarble = spaces[row][column]; bool cycle = true; // NECESITO OTRA IDEA, ESTO ESTA BIEN PERO LOS DATOS INÚTILES do { switch (direction) { case Direction.Left: if (column - 1 >= 0 &&) { break; } case Direction.FrontLeft: nextCell = board.Get_NextCellFrontLeft(cell); break; case Direction.FrontRight: nextCell = board.Get_NextCellFrontRight(cell); break; case Direction.Right: nextCell = board.Get_NextCellRight(cell); break; case Direction.BackRight: nextCell = board.Get_NextCellBackRight(cell); break; case Direction.BackLeft: nextCell = board.Get_NextCellBackLeft(cell); break; default: actualMarble = null; break; } }while (cycle); return(selectedMarbles); }
public int Evaluate(PLAYER_COLOR player) { if (IsWinningPosition(player)) { return(1000); } if (IsWinningPosition(Opponent(player))) { return(-1000); } int evaluationSum = 0; // canicas del AI en el medio for (byte row = 0; row < rows; row++) { int maxcolumn = spaces[row].Length; for (byte column = 0; column < maxcolumn; column++) { if (spaces[row][column] == player) { evaluationSum += evaluationMatrix[row][column]; } else if (spaces[row][column] == Opponent(player)) { evaluationSum -= evaluationMatrix[row][column]; } if (isHexagon(row, column)) { evaluationSum += 10; } } } // Número de canicas amigas y enemigas Debug.Log(evaluationSum); return(evaluationSum); }
public int Evaluate(PLAYER_COLOR player) { if (IsWinningPosition(player)) { return(1000); } if (IsWinningPosition(Opponent(player))) { return(-1000); } int evaluationSum = 0; // canicas del AI en el medio for (byte row = 0; row < rows; row++) { int maxcolumn = spaces[row].Length; for (byte column = 0; column < maxcolumn; column++) { if (spaces[row][column] == player) { evaluationSum += evaluationMatrix[row][column]; } else if (spaces[row][column] == Opponent(player)) { evaluationSum -= evaluationMatrix[row][column]; } } } // Número de canicas amigas y enemigas // Canicas agrupadas //Posiciones de ataque enemigas y aliadas return(evaluationSum); }
public void HashMove(List <MoveMarble> moves, PLAYER_COLOR player) //modificar todo el cuerpo { int piece, zobristKey; List <keyposition> rowCols = new List <keyposition>(); foreach (MoveMarble move in moves) { PLAYER_COLOR current; PLAYER_COLOR next; if (!move.CurrentCell.Marble) { current = PLAYER_COLOR.NONE; } else if (move.CurrentCell.Marble.isWhite) { current = PLAYER_COLOR.WHITE; } else { current = PLAYER_COLOR.BLACK; } if (!move.CurrentCell.Marble) { next = PLAYER_COLOR.NONE; } else if (move.CurrentCell.Marble.isWhite) { next = PLAYER_COLOR.WHITE; } else { next = PLAYER_COLOR.BLACK; } for (byte row = 0; row < rows; row++) { int maxcolumn = spaces[row].Length; for (byte column = 0; column < maxcolumn; column++) { if (move.CurrentCell.Row == row && move.CurrentCell.Column == column && move.hasToDestroy) { spaces[row][column] = PLAYER_COLOR.NONE; } else if (move.CurrentCell.Row == row && move.CurrentCell.Column == column && spaces[row][column] == player) { spaces[row][column] = PLAYER_COLOR.NONE; } else if (move.NextCell != null && move.NextCell.Row == row && move.NextCell.Column == column && spaces[row][column] == PLAYER_COLOR.NONE) { if (current == PLAYER_COLOR.WHITE && (next == PLAYER_COLOR.BLACK || next == PLAYER_COLOR.NONE)) { spaces[row][column] = PLAYER_COLOR.WHITE; rowCols.Add(new keyposition(row, column, spaces[row][column])); } else if (current == PLAYER_COLOR.BLACK && (next == PLAYER_COLOR.WHITE || next == PLAYER_COLOR.NONE)) { spaces[row][column] = PLAYER_COLOR.BLACK; rowCols.Add(new keyposition(row, column, spaces[row][column])); } else if (current == next) { spaces[row][column] = current; } } } } } rowCols.Add(new keyposition(moves[moves.Count - 1].CurrentCell.Row, moves[moves.Count - 1].CurrentCell.Column, activePlayer)); //Se modifica mas de una posicion al mismo tiempo asi que hay que hacer un bucle for (int i = 0; i < rowCols.Count; i++) { if (rowCols[i].changedTo == PLAYER_COLOR.BLACK) { piece = 0; } else { piece = 1; } zobristKey = zobristKeys.GetKey((int)rowCols[i].row, (int)rowCols[i].column, piece); hashValue ^= zobristKey; } }
public keyposition(int _row, int _column, PLAYER_COLOR _changedTo) { row = _row; column = _column; changedTo = _changedTo; }
public void HashMove(List <MoveMarble> moves, PLAYER_COLOR player) //modificar todo el cuerpo { int[] positionsRow = new int[moves.Count]; int[] positionsColumn = new int[moves.Count]; int posIndex = 0; int piece, zobristKey; foreach (MoveMarble move in moves) { bool white = move.CurrentCell.Marble.isWhite; for (byte row = 0; row < rows; row++) { int maxcolumn = spaces[row].Length; for (byte column = 0; column < maxcolumn; column++) { if (move.CurrentCell.Row == row && move.CurrentCell.Column == column && move.hasToDestroy) { spaces[row][column] = PLAYER_COLOR.NONE; } else if (move.CurrentCell.Row == row && move.CurrentCell.Column == column && spaces[row][column] == player) { spaces[row][column] = PLAYER_COLOR.NONE; } else if (move.NextCell != null && move.NextCell.Row == row && move.NextCell.Column == column && spaces[row][column] == PLAYER_COLOR.NONE) { if (white) { spaces[row][column] = PLAYER_COLOR.WHITE; } else { spaces[row][column] = PLAYER_COLOR.BLACK; } positionsRow[posIndex] = row; positionsColumn[posIndex] = column; posIndex++; } } } } //Se modifica mas de una posicion al mismo tiempo asi que hay que hacer un bucle for (int i = 0; i < positionsRow.Length; i++) { if (player == PLAYER_COLOR.BLACK) { piece = 0; } else { piece = 1; } zobristKey = zobristKeys.GetKey(positionsRow[i], positionsColumn[i], piece); hashValue ^= zobristKey; } /* * int filledRow = 0, position, piece, zobristKey; * * for (int row = rows - 1; row >= 0; row--) * { * if (IsEmptySpace(row, column)) * { * spaces[row][column] = player; * filledRow = row; * break; * } * } * * position = filledRow * columns + column; * if (player == PLAYER_COLOR.BLACK) * { * piece = 0; * } * else * { * piece = 1; * } * * zobristKey = zobristKeys.GetKey(position, piece); * * hashValue ^= zobristKey;*/ }