//Get the average score for current player rolling all possible combinations private double PropabilityScore(Player.Color myColor) { var allDiceRoll = AllRolls(); var scores = new List <double>(); foreach (var roll in allDiceRoll) { Game.FakeRoll(roll.dice1, roll.dice2); var bestScore = double.MinValue; var seqs = GenerateMovesSequence(); foreach (var s in seqs) { var hits = DoSequence(s); var score = EvaluatePoints(myColor) + EvaluateCheckers(myColor); if (score > bestScore) { bestScore = score; } UndoSequence(s, hits); } int m = roll.dice1 == roll.dice2 ? 1 : 2; // dice roll with not same value on dices are twice as probable. 2 / 36, vs 1 / 36 if (seqs.Any()) { scores.Add(bestScore * m); } // Get best score of each roll, and make an average. // some rolls are more probable, multiply them // some rolls will be blocked or partially blocked } if (!scores.Any()) { return(-100000); } return(scores.Average()); }
public Disk(int row, int col, Player.Color color) { Pair pair = new Pair(row, col); this.pos = pair; this.color = color; }
public bool isValid(Pair to, Pair from, PegBoard pegBoard, Player.Color currentPlayerColor) { int moveUpDown = from.row - to.row; int moveLeftRight = from.col - to.col; if (pegBoard.checkColor(from) != currentPlayerColor || // correct color pegBoard.isEmpty(from) || // selected empty peg slot !pegBoard.isEmpty(to)) // dropped on occupied slot { // conditions for immediate failure return(false); } else if (Math.Abs(moveUpDown) == 1 || Math.Abs(moveLeftRight) == 1) { // jump OR move 1 return(true); } else if (Math.Abs(moveUpDown) == 2 ^ Math.Abs(moveLeftRight) == 2) // xor jump (2) { // Jumps A color and Jumps OTHER color return(!pegBoard.isEmpty(from.row - moveUpDown / 2, from.col - moveLeftRight / 2) && pegBoard.checkColor(from.row - moveUpDown / 2, from.col - moveLeftRight / 2) != currentPlayerColor); } else { // Don't jump the rainbow! return(false); } }
public void ChangeColor(Player.Color color) { switch (color) { case Player.Color.White: colorMeshes[0].SetActive(true); break; case Player.Color.Blue: colorMeshes[1].SetActive(true); AudioSource wind = GetComponent <AudioSource>(); wind.Play(); //AudioClip.PlayOneShot (wind, 0.0F); break; case Player.Color.Red: colorMeshes[2].SetActive(true); break; case Player.Color.Yellow: colorMeshes[3].SetActive(true); break; case Player.Color.Green: colorMeshes[4].SetActive(true); break; } }
public void TurnOffMesh(Player.Color color) { switch (color) { case Player.Color.White: colorMeshes[0].SetActive(false); break; case Player.Color.Blue: colorMeshes[1].SetActive(false); break; case Player.Color.Red: colorMeshes[2].SetActive(false); break; case Player.Color.Yellow: colorMeshes[3].SetActive(false); break; case Player.Color.Green: colorMeshes[4].SetActive(false); break; } }
public void AddCheckers(int count, Player.Color color, int point) { for (int i = 0; i < count; i++) { Points.Single(p => p.GetNumber(color) == point).Checkers.Add(new Checker { Color = color }); } }
internal async Task ConnectAndListen(WebSocket webSocket, Player.Color color, Db.User dbUser, bool playAi) { if (color == Player.Color.Black) { Client1 = webSocket; Game.BlackPlayer.Id = dbUser != null ? dbUser.Id : Guid.Empty; Game.BlackPlayer.Name = dbUser != null ? dbUser.Name : "Guest"; Game.BlackPlayer.Photo = dbUser != null && dbUser.ShowPhoto ? dbUser.PhotoUrl : ""; Game.BlackPlayer.Elo = dbUser != null ? dbUser.Elo : 0; if (Game.IsGoldGame) { Game.BlackPlayer.Gold = dbUser != null ? dbUser.Gold - firstBet : 0; Game.Stake = firstBet * 2; } if (playAi) { var aiUser = Db.BgDbContext.GetDbUser(Db.User.AiUser); Game.WhitePlayer.Id = aiUser.Id; Game.WhitePlayer.Name = aiUser.Name; // TODO: AI image Game.WhitePlayer.Photo = aiUser.PhotoUrl; Game.WhitePlayer.Elo = aiUser.Elo; if (Game.IsGoldGame) { Game.WhitePlayer.Gold = aiUser.Gold; } Engine = new Ai.Engine(Game); CreateDbGame(); StartGame(); if (Game.CurrentPlayer == Player.Color.White) { await EnginMoves(Client1); } } await ListenOn(webSocket); } else { if (playAi) { throw new ApplicationException("Ai always plays as white. This is not expected"); } Client2 = webSocket; Game.WhitePlayer.Id = dbUser != null ? dbUser.Id : Guid.Empty; Game.WhitePlayer.Name = dbUser != null ? dbUser.Name : "Guest"; Game.WhitePlayer.Photo = dbUser != null && dbUser.ShowPhoto ? dbUser.PhotoUrl : ""; Game.WhitePlayer.Elo = dbUser != null ? dbUser.Elo : 0; if (Game.IsGoldGame) { Game.WhitePlayer.Gold = dbUser != null ? dbUser.Gold - firstBet : 0; } CreateDbGame(); StartGame(); await ListenOn(webSocket); } }
/// <summary>Sets the piece up.</summary> /// <param name="type">The piece's type.</param> /// <param name="color">The piece's color.</param> /// <param name="x">The x-value.</param> /// <param name="y">The y-value.</param> /// <param name="automaticallyUpdateTransform">Whether the transform's position should be updated. Defaults to true.</param> public void SetUp(BoardPiece.Type type, Player.Color color, int x, int y, bool automaticallyUpdateTransform = true) { //set the type, color, (x, y) and name this.type = type; this.color = color; SetXY(x, y, automaticallyUpdateTransform); name = string.Format("{0} {1}", type.ToString(), color.ToString()); //update the sprite UpdateSprite(); }
private static double EvaluatePoints(Player.Color myColor, Game game) { if (myColor == Player.Color.White) // Higher score for white when few checkers and black has many checkers left { return(game.BlackPlayer.PointsLeft - game.WhitePlayer.PointsLeft); } else { return(game.WhitePlayer.PointsLeft - game.BlackPlayer.PointsLeft); } }
private Player.Color oppositeColor(Player.Color color) { if (color == Player.Color.Black) { return(Player.Color.White); } else { return(Player.Color.Black); } }
private double EvaluatePoints(Player.Color myColor) { if (myColor == Player.Color.Black) { return(Game.BlackPlayer.PointsLeft - Game.WhitePlayer.PointsLeft); } else { return(Game.WhitePlayer.PointsLeft - Game.BlackPlayer.PointsLeft); } }
public int myPegCount(Player.Color color) { if (color == Player.Color.White) { return(_whitePegCount); } else { return(_blackPegCount); } }
private void incDiskCount(Player.Color color) { // add new disk if (color == Player.Color.Black) { _blackDiskCount++; } else { _whiteDiskCount++; } }
public MoveHeuristic(Player.Color Me) { if (Me.Equals(Player.Color.Red)) { MyStatus = Cell.CellStatus.OccupiedRed; OpponentStatus = Cell.CellStatus.OccupiedBlack; } else { MyStatus = Cell.CellStatus.OccupiedBlack; OpponentStatus = Cell.CellStatus.OccupiedRed; } }
public bool sameColorDiskAt(int row, int col, Player.Color currentColor) { bool sameColor = false; if (this.board[row, col] != null) { if (this.board[row, col].color == currentColor) { sameColor = true; } } return(sameColor); }
private void adjDiskCount(Player.Color color) { // flip opposite disk if (color == Player.Color.Black) { _blackDiskCount++; _whiteDiskCount--; } else { _whiteDiskCount++; _blackDiskCount--; } }
public int movesFromWin(Player.Color color) { int count; if (color == Player.Color.White) { count = movesFromWhiteWin(0, 0); } else { count = movesFromBlackWin(5, 0); } return(count); }
/// <summary> /// Private Constructor used to initialize child node /// </summary> /// <param name="currentColor"></param> ---> will switch color /// <param name="pegBoard"></param> /// <param name="diskBoard"></param> /// <param name="minimaxValue"></param> ---> will switch min/max /// <param name="to"></param> /// <param name="from"></param> /// <param name="levelInTree"></param> /// <param name="aiColor"></param> private TreeNode(Player.Color currentColor, PegBoard pegBoard, DiskBoard diskBoard, MiniMax minimaxValue, Pair to, Pair from, int levelInTree, Player.Color aiColor, int movesFromWin, int maxTreeDepth, double middlePegHeuristic) { this._pegBoard = pegBoard; this._diskBoard = diskBoard; this._moveMade = new PieceMove(); this._moveMade.to = to; this._moveMade.from = from; this._levelInTree = levelInTree; this._aiColor = aiColor; this._movesFromWin = movesFromWin - 1; this._maxTreeDepth = maxTreeDepth; this._middlePegHeuristic = middlePegHeuristic; if (maxTreeDepth == 1) { this._difficultyLevel = Difficulty.Easy; } else if (maxTreeDepth == 3) { this._difficultyLevel = Difficulty.Medium; } else { this._difficultyLevel = Difficulty.Hard; } // Switch colors if (currentColor == Player.Color.White) { this._currentColor = Player.Color.Black; } else { this._currentColor = Player.Color.White; } // Switch minimaxValue if (minimaxValue == MiniMax.Max) { this._minimaxValue = MiniMax.Min; } else { this._minimaxValue = MiniMax.Max; } }
private bool isValid(Pair to, Pair from, PegBoard pegBoard, Player.Color currentPlayerColor) { int moveUpDown = from.row - to.row; int moveLeftRight = from.col - to.col; if (to.row < 0 || to.col < 0 || from.row < 0 || from.col < 0 || to.row > boardSize || to.col > boardSize || from.row > boardSize || from.col > boardSize) { return(false); } else if (pegBoard.checkColor(from) != currentPlayerColor || // correct color pegBoard.isEmpty(from) || // selected empty peg slot !pegBoard.isEmpty(to)) // dropped on occupied slot { // Conditions for immediate failure return(false); } else if (Math.Abs(moveUpDown) == 1 && Math.Abs(moveLeftRight) == 1) { // Jump return(true); } else if (Math.Abs(moveUpDown) + Math.Abs(moveLeftRight) == 1) { // Move peg over 1 return(true); } else if (Math.Abs(moveUpDown) + Math.Abs(moveLeftRight) == 2) { // jump (2,0) or (0,2) --> the (1,1) case has already been tested return(!pegBoard.isEmpty(from.row - moveUpDown / 2, from.col - moveLeftRight / 2) && pegBoard.checkColor(from.row - moveUpDown / 2, from.col - moveLeftRight / 2) != currentPlayerColor); // Jumps A color and Jumps OTHER color } else { // Don't jump the rainbow! return(false); } }
private void HandleColorSwap() { Player.Color playerColor = player.currentColor; cc.TurnOffMesh(playerColor); cc.ChangeColor(fairy.GetColor()); player.currentColor = fairy.GetColor(); fairycc.TurnOffMesh(fairy.GetColor()); fairycc.ChangeColor(playerColor); fairy.SetColor(playerColor); if (player.currentColor == Player.Color.Blue) { player.TurnDoubleJumpOn(); } else { player.TurnDoubleJumpOff(); } }
public void movePeg(Player.Color color, Pair to, Pair from) { if (Math.Abs(to.row - from.row) == 2 ^ Math.Abs(to.col - from.col) == 2) { // Capture then move capturePeg(color, to, from); } foreach (Peg peg in this.pegList) { if (peg.isLocated(from)) { this.pegList.Remove(peg); this.pegList.Add(new Peg(to, peg.color)); return; } } }
private int ApplyHeuristic(Player.Color aiColor) { int heuristicValue = 0; if (this._difficultyLevel == Difficulty.Easy) { heuristicValue = EasyHeuristic(aiColor); } else if (this._difficultyLevel == Difficulty.Medium) { heuristicValue = MediumHeuristic(aiColor); } else { heuristicValue = HardHeuristic(aiColor); } this._heuristicValue = heuristicValue; return(heuristicValue); }
private double EvaluateCheckers(Player.Color myColor) { double score = 0; var inBlock = false; var counter = 0; for (int i = 1; i < 25; i++) { var point = Game.Points[i]; if (point.MyBlock(myColor)) { if (inBlock) { counter++; } else { counter = 1; } inBlock = true; } else { if (inBlock) { score += Math.Pow(counter, 2); counter = 0; } inBlock = false; } } if (inBlock) { score += Math.Pow(counter, 2); } score += Game.GetHome(myColor).Checkers.Count * 10; return(score); }
/// <summary> /// Public Constructor /// </summary> /// <param name="player"></param> /// <param name="pegBoard"></param> /// <param name="diskBoard"></param> /// <param name="minimaxValue"></param> public TreeNode(Player player, PegBoard pegBoard, DiskBoard diskBoard, MiniMax minimaxValue, int treeDepth) { this._minimaxValue = minimaxValue; this._pegBoard = pegBoard; this._currentColor = this._aiColor = player.color; this._diskBoard = diskBoard; this._movesFromWin = diskBoard.movesFromWin(); this._maxTreeDepth = treeDepth; if (treeDepth == 1) { this._difficultyLevel = Difficulty.Easy; } else if (treeDepth == 3) { this._difficultyLevel = Difficulty.Medium; } else { this._difficultyLevel = Difficulty.Hard; } }
public void capturePeg(Player.Color color, Pair to, Pair from) { // Find the peg foreach (Peg peg in this.pegList) { // Remove jumped peg if (peg.isLocated((from.row + to.row) / 2, (from.col + to.col) / 2)) { this.pegList.Remove(peg); if (color == Player.Color.White) { this._blackPegCount--; } else { this._whitePegCount--; } return; } } }
public void placeDisk(Player.Color color, Pair to, Pair from) { int row = (from.row + to.row) / 2; int col = (from.col + to.col) / 2; // place onto empty if (this.board[row, col] == null) { this.board[row, col] = new Disk(row, col, color); incDiskCount(color); } else if ((row == 0 && col == 0) || (row == 5 && col == 0) || (row == 0 && col == 5) || (row == 5 && col == 5)) { } // flip over occupied else if (this.board[row, col].color != color) { this.board[row, col] = new Disk(row, col, color); adjDiskCount(color); } }
internal async Task ConnectAndListen(WebSocket webSocket, Player.Color color, Db.User dbUser, bool playAi) { if (color == Player.Color.Black) { Client1 = webSocket; Game.BlackPlayer.Id = dbUser != null ? dbUser.Id : Guid.Empty; Game.BlackPlayer.Name = dbUser != null ? dbUser.Name : "Guest"; if (playAi) { var aiUser = Db.BgDbContext.GetDbUser(Db.User.AiUser); Game.WhitePlayer.Id = aiUser.Id; Game.WhitePlayer.Name = aiUser.Name; Engine = new Ai.Engine(Game); CreateDbGame(); StartGame(); if (Game.CurrentPlayer == Player.Color.White) { await EnginMoves(Client1); } } await ListenOn(webSocket); } else { if (playAi) { throw new ApplicationException("Ai always playes as white. This is not expected"); } Client2 = webSocket; Game.WhitePlayer.Id = dbUser != null ? dbUser.Id : Guid.Empty; Game.WhitePlayer.Name = dbUser != null ? dbUser.Name : "Guest"; CreateDbGame(); StartGame(); await ListenOn(webSocket); } }
public void Fill(Player.Color color) { if (!filled && OnStoneFilled != null) { if (color == Player.Color.Red) { sr.sprite = redFilled; } else if (color == Player.Color.Blue) { sr.sprite = blueFilled; } else if (color == Player.Color.Green) { sr.sprite = greenFilled; } else { sr.sprite = yellowFilled; } filled = true; OnStoneFilled(); } }
// Start is called before the first frame update void Start() { currColor = Player.Color.White; }
public void SetColor(Player.Color color) { currColor = color; }