// Method to place a tile on the board. public void UpdateAI() { int highestX = -1; //The x co-ordinate of the current highest scoring tile int highestY = -1; //The y co-ordinate of the current highest scoring tile int highestScore = 0; //The highest score found so far int currentScore; //The score of the current tile being compared if (boardBehaviour.currentPlayer == playerNumber) { for (int y = 0; y < 8; y++) { for (int x = 0; x < 8; x++) { if (boardBehaviour.CanPlaceTile(x, y, playerNumber)) { currentScore = boardBehaviour.GetTileScore(x, y, playerNumber); if (currentScore > highestScore && boardBehaviour.GetTileState(x, y) == 0) { highestScore = currentScore; highestX = x; highestY = y; } } } } if (highestX != -1 && highestY != -1) { boardBehaviour.SetTileState(highestX, highestY, playerNumber); } boardBehaviour.TurnComplete(); } }
// Update is called once per frame void Update() { int currentPlayerToDisplay = 1; if (player1.enabled && player2.enabled) { currentPlayerToDisplay = boardBehaviour.currentPlayer; } if (boardBehaviour.GetTileState(x, y) == 0) { contents = boardBehaviour.GetTileScore(x, y, currentPlayerToDisplay); if (contents < 10 && contents > 0) { textMesh.text = contents.ToString(); } else if (contents > 9) { textMesh.text = "+"; } else { textMesh.text = ""; } } else { textMesh.text = ""; } Color tempColour = textMesh.color; tempColour.a = (0.3f + 0.1f * contents) + (0.05F - (float)(rand.NextDouble() / 10)); textMesh.color = tempColour; }
/// <summary> /// Finds the highest scoring move, then simulates placing it. Returns a Placement structure. /// </summary> /// <returns>The highest scoring move.</returns> /// <param name="gameBoard">Game board.</param> /// <param name="player">Player.</param> Placement FindHighestScoringMove(int[,] gameBoard, int player, int originalX, int originalY) { Placement highestScoringMove = new Placement(); int tempHighestX = 0; int tempHighestY = 0; int tempHighestScore = -1; int currentScore = 0; for (int y = 0; y < 8; y++) { for (int x = 0; x < 8; x++) { currentScore = 0; if (boardBehaviour.CanPlaceTile(x, y, player, gameBoard)) { currentScore = boardBehaviour.GetTileScore(x, y, player, gameBoard); } if (currentScore > tempHighestScore) { tempHighestX = x; tempHighestY = y; tempHighestScore = currentScore; } } } highestScoringMove.x = originalX; highestScoringMove.y = originalY; highestScoringMove.board = new int[8, 8]; int[,] tempBoard = boardBehaviour.SetTileState(tempHighestX, tempHighestY, player, gameBoard); Array.Copy(tempBoard, highestScoringMove.board, tempBoard.Length); return(highestScoringMove); }