public double GetPoints(Mancala game, bool player1) { if (game.CheckEnd()) { if (player1) { return(game.Player1Well[0] + game.Player1Holes.Sum(x => x) - game.Player2Well[0] - game.Player2Holes.Sum(x => x)); } else { return(game.Player2Well[0] + game.Player2Holes.Sum(x => x) - game.Player1Well[0] - game.Player1Holes.Sum(x => x)); } } else { if (player1) { return(game.Player1Well[0] - game.Player2Well[0]); } else { return(game.Player2Well[0] - game.Player1Well[0]); } } }
// gameMode = 1 - H vs H // gameMode = 2 - H vs Ai // gameMode = 3 - Ai vs Ai // gameMode = 4 - H vs Ai_AB // gameMode = 5 - Ai_AB vs Ai_AB // gameMode = 6 - Ai_AB vs Ai // For deepCopy public Mancala(Mancala mancala) { firstMove = mancala.firstMove; player1Turn = mancala.player1Turn; Player1 = mancala.Player1; Player1Holes = mancala.Player1Holes.Select(x => x).ToArray(); Player1Well = mancala.Player1Well.Select(x => x).ToArray(); Player2 = mancala.Player2; Player2Holes = mancala.Player2Holes.Select(x => x).ToArray(); Player2Well = mancala.Player2Well.Select(x => x).ToArray(); this.evaluatePointsP1 = mancala.evaluatePointsP1; this.evaluatePointsP2 = mancala.evaluatePointsP2; Player1Depth = mancala.Player1Depth; Player2Depth = mancala.Player2Depth; }
public double GetPoints(Mancala game, bool player1) { double result = 0; if (player1) { // Winning it's good if (game.CheckEnd()) { return(game.Player1Well[0] + game.Player1Holes.Sum(x => x) - game.Player2Well[0] - game.Player2Holes.Sum(x => x)); } // Game continue, so we calculate points like above functions // Adding points when we have it double raisingVal = 1; for (int i = 0; i < game.Player1Holes.Length; i++) { if (game.Player1Holes[i] == i + 1) { result += raisingVal; // Because it can combo up if (i > 0 && game.Player1Holes[0] == 0) { result += ComboValue; } } raisingVal += 0.5; } result += game.Player1Holes.Sum(x => x) * this.HoleValue; result += game.Player1Well[0] * WellValue; // Subtracting points from raisingVal = 1; for (int i = game.Player1Holes.Length - 1; i >= 0; i--) { if (game.Player2Holes[i] == i + 1) { result -= raisingVal; // Because it can combo up if (i > 0 && game.Player2Holes[0] == 0) { result -= ComboValue; } } raisingVal += 0.5; } result -= game.Player2Holes.Sum(x => x) * this.HoleValue; result -= game.Player2Well[0] * WellValue; return(result); } else { if (game.CheckEnd()) { return(game.Player2Well[0] + game.Player2Holes.Sum(x => x) - game.Player1Well[0] - game.Player1Holes.Sum(x => x)); } // Game continue, so we calculate points like above functions // Abosite adding and Subtracting, than above double raisingVal = 1; for (int i = 0; i < game.Player2Holes.Length; i++) { if (game.Player1Holes[i] == i + 1) { result -= raisingVal; // Because it can combo up if (i > 0 && game.Player1Holes[0] == 0) { result -= ComboValue; } } raisingVal -= 0.5; } result -= game.Player1Holes.Sum(x => x) * this.HoleValue; result -= game.Player1Well[0] * WellValue; // Subtracting points from raisingVal = 1; for (int i = game.Player2Holes.Length - 1; i >= 0; i--) { if (game.Player2Holes[i] == i + 1) { result += raisingVal; // Because it can combo up if (i > 0 && game.Player2Holes[0] == 0) { result += ComboValue; } } raisingVal += 0.5; } result += game.Player2Holes.Sum(x => x) * this.HoleValue; result += game.Player2Well[0] * WellValue; return(result); } }