private void Window_Loaded(object sender, RoutedEventArgs e) { Console.WriteLine($"**** Window_Loaded ****"); for (int n = 0; n < 64; n++) { StackPanel sp = ChB[n].StPanel; CheckerColor col = ChB[n].Col; sp.Tag = n; switch (col) { case CheckerColor.Unknown: break; case CheckerColor.Black: SetCheckerToStackPanel(n, CheckerColor.Black); break; case CheckerColor.White: SetCheckerToStackPanel(n, CheckerColor.White); break; } Console.WriteLine($"n= {sp.Tag} sp = {sp.Name} Col = {col}"); } Console.WriteLine($"********"); Console.WriteLine(); new CStepDialog().Show(); }
private void DrawChecker(PaintEventArgs e, CheckerColor checkerColor, int x, int y, bool highlight) { // Create a path that consists of a single ellipse. GraphicsPath path = new GraphicsPath(); path.AddEllipse(x, y, checkerRadiusSize, checkerRadiusSize); // Use the path to construct a brush. PathGradientBrush pthGrBrush = new PathGradientBrush(path); // Set the color at the center of the path. pthGrBrush.CenterColor = Color.FromArgb(215, 225, 255, 255); // Set the color along the entire boundary of the path. // 2nd argument is 255 - red or 0 - black if (highlight == false) { Color[] colors = { Color.FromArgb(255, checkerColor == CheckerColor.Red ? 255 : 0, 0, 0) }; pthGrBrush.SurroundColors = colors; e.Graphics.FillEllipse(pthGrBrush, x, y, checkerRadiusSize, checkerRadiusSize); } else { Color[] colors = { Color.FromArgb(255, checkerColor == CheckerColor.Red ? 255 : 22, 22, 255) }; pthGrBrush.SurroundColors = colors; e.Graphics.FillEllipse(pthGrBrush, x, y, checkerRadiusSize, checkerRadiusSize); } }
//Sprawdza warunki czy gra nadal się toczy. public static bool IfGameContinues(Square[,] board, CheckerColor playerColor, CheckerColor aiColor) { bool playerCanMove = false; bool aiCanMove = false; for (int x = 0; x < 8; x++) { for (int y = 0; y < 8; y++) { if (board[x, y].Color == playerColor && Utils.PossibleMoves(board, new Position(x, y)).Length != 0) { playerCanMove = true; } if (board[x, y].Color == aiColor && Utils.PossibleMoves(board, new Position(x, y)).Length != 0) { aiCanMove = true; } if (playerCanMove && aiCanMove) { return(true); } } } return(playerCanMove && aiCanMove ? true : false); }
public bool IsBiggestInGoal(CheckerColor currentPlayer, BoardPosition boardPosition, int checkerindex) { if (CurrentPlayerIsInGoal(currentPlayer)) { if (currentPlayer == CheckerColor.Red) { for (int i = checkerindex - 1; i >= 19; i--) { if (boardPosition.CountAtPosition(i) != 0) { if (boardPosition.ColorAtPosition(i) == CheckerColor.Red) { return(false); } } } } else if (currentPlayer == CheckerColor.Black) { for (int i = checkerindex + 1; i <= 6; i++) { if (boardPosition.CountAtPosition(i) != 0) { if (boardPosition.ColorAtPosition(i) == CheckerColor.Black) { return(false); } } } } return(true); } return(false); }
public StateChangedEventArgs(BoardPosition boardPosition, Dice dice, CheckerColor checkerColor, Logic logic) { BoardPosition = boardPosition; Dice = dice; CheckerColor = checkerColor; Logic = logic; }
public void DrawChekers(PictureBox currPicture, CheckerColor currColor, int checkers, bool isTopLine) { Bitmap bmp = new Bitmap(currPicture.Width, currPicture.Height); Graphics g = Graphics.FromImage(bmp); g.Clear(Color.Transparent); SolidBrush brush; if (currColor == CheckerColor.Black) { brush = new SolidBrush(Color.Black); } else { brush = new SolidBrush(Color.Green); } for (int i = 0; i < checkers; i++) { if (isTopLine) { g.FillEllipse(brush, 0, i * CheckerHeight, CheckerWidth, CheckerHeight); } else { g.FillEllipse(brush, 0, Point0.Height - CheckerHeight - i * CheckerHeight, CheckerWidth, CheckerHeight); } } currPicture.Image = bmp; brush.Dispose(); g.Dispose(); }
public void RemoveCheckerFromTriangle(int triangleNumber, CheckerColor checkerColor) { if (checkerColor != Triangles[triangleNumber].CheckersColor) { Triangles[triangleNumber].NumOfCheckers--; } }
public void AddCheckerToTriangle(int triangleNumber, CheckerColor checkerColor) { if (checkerColor != Triangles[triangleNumber].CheckersColor) { Triangles[triangleNumber].NumOfCheckers++; } }
public void TurnActiveColorSide() { if (!_repeatMove) { _activeCheckerColor = _activeCheckerColor == CheckerColor.WHITE ? CheckerColor.BLACK : CheckerColor.WHITE; } }
public void AddNewCheckers(Point p, CheckerColor color, int count) { for (; count > 0; count--) { p.Checkers.Push(new Checker(nextCheckerId++, color, p.Position)); } }
// actions public int RollStartDice(CheckerColor color) { if (GameStarted || GameOver || startRollNumbers.ContainsKey(color)) { throw new RollDiceNotAllowedException(); } var ret = RollDiceOnce(); startRollNumbers[color] = ret; if (startRollNumbers.Count == 2) { var rollNumber1 = startRollNumbers[CheckerColor.White]; var rollNumber2 = startRollNumbers[CheckerColor.Black]; CurrentRoll = new Roll(rollNumber1, rollNumber2); if (rollNumber1 != rollNumber2) { GameStarted = true; CurrentColor = rollNumber1 > rollNumber2 ? CheckerColor.White : CheckerColor.Black; remainingRollNumbers.Add(CurrentRoll.Number1); remainingRollNumbers.Add(CurrentRoll.Number2); } startRollNumbers.Clear(); } return(ret); }
//if can play - reach here private void PlayMove(int source, int target, CheckerColor color, int move) { Board.GameBoard[source].NumOfCheckers--; if (Board.GameBoard[source].NumOfCheckers == 0 && source != 0 && source != 25) { Board.GameBoard[source].Color = CheckerColor.None; } if (Board.GameBoard[target].IsEdible(color)) { if (color == CheckerColor.Black) { Board.GameBoard[0].NumOfCheckers++; } else { Board.GameBoard[25].NumOfCheckers++; } Board.GameBoard[target].NumOfCheckers = 0; } if (Board.GameBoard[target].NumOfCheckers == 0) { Board.GameBoard[target].Color = color; } Board.GameBoard[target].NumOfCheckers++; Moves[move] = 0; if (!AreAvailableMoves() || !CanPlay()) { TurnStatus = TurnStatus.EndTurn; } }
private bool CanMove(CheckerColor color, int source, int target) { //out of range if (target < 1 || target > 24) { return(false); } //right player if (color != Board.GameBoard[source].Color) { return(false); } //wrong direction if ((color == CheckerColor.Black && source <= target) || (color == CheckerColor.White && target <= source)) { return(false); } //If source is empty cell if (Board.GameBoard[source].IsEmpty()) { return(false); } //Target is occupied if (!Board.GameBoard[target].CanAddChecker(color)) { return(false); } return(true); }
//Given a position and a color, assumes the position is with regards to the other color and //converts it to the perspective of the given color private static int convertTo(CheckerColor color, int i) { if (color == BLACK) { if (i == WHITE.GetBar()) { return(BLACK.GetBar()); } if (i == WHITE.BearOffPositionID()) { return(BLACK.BearOffPositionID()); } return(25 - i); } if (i == color.OppositeColor().GetBar()) { return(color.GetBar()); } if (i == color.OppositeColor().BearOffPositionID()) { return(color.BearOffPositionID()); } return(25 - i); }
public void RemoveChecker() { CheckersAmount--; if (CheckersAmount < 1) { Color = CheckerColor.Empty; } }
/// <summary> /// Create new checker instance. /// </summary> public Checker(int id, Square square, CheckerColor color) { Id = id; Square = square; Color = color; IsSuperChecker = false; IsBeat = false; }
internal bool CheckerWasCaptured(CheckerColor playerColor, int to) { try { return(Points[to].GetAmount() == 1 && Points[to].GetTopChecker().Color != playerColor); } catch (ArgumentOutOfRangeException) { return(false); } }
private Point GetBearOffPoint(CheckerColor color) { if (color == White) { return(WhiteBearOff); } return(BlackBearOff); }
private Point GetOnBarPoint(CheckerColor color) { if (color == White) { return(WhiteBar); } return(BlackBar); }
public List <int> GetMoveableCheckers(CheckerColor color) { if (color != turnColor) { throw new InvalidOperationException("Cant get moveable checkers for player " + color + " when it is " + color.OppositeColor() + "'s turn"); } return(MovesCalculator.GetMoveableCheckers(currentGameBoardState, color, movesLeft).ToList()); }
private void changeTurns(CheckerColor color) { recalculateMoves(); turnColor = color; this.PreviousTurn = this.CurrentTurn; this.CurrentTurn = new Turn(color, new List <Move>(), new List <int>(movesLeft)); NumberOfTurnsMade++; }
internal void MakeMove(BackgammonGame model, CheckerColor color) { if (RemotePlayer == null) { Instantiate(model, color); } RemotePlayer.MakeMove(); }
public Checker(int row, int column, Game game, Image img, CheckerColor color) { Game = game; Color = color; Row = row; Column = column; Image = img; }
public int?GetStartRollNumber(CheckerColor color) { if (startRollNumbers.TryGetValue(color, out int val)) { return(val); } return(null); }
internal MoveState(GameBoardState state, CheckerColor color, int position, List <int> movesLeft, List <Change> changes) { this.state = state; this.color = color; this.position = position; this.movesLeft = movesLeft; this.changes = changes; }
public int pip(CheckerColor color) { if (color == Black) { return(this.InvertColor().pip(White)); } return(gameBoard.Where(kv => kv.Key >= 1 && kv.Key <= 24).Where(kv => kv.Value > 0).Select(kv => kv.Key * kv.Value).Sum() + getCheckersOnBar(White) * 25); }
public int capturableCheckers(CheckerColor color) { if (color == Black) { return(InvertColor().capturableCheckers(White)); } return(gameBoard.Where(kv => kv.Key >= 1 && kv.Key <= 24).Where(kv => kv.Value == 1).Count()); }
protected Player(CheckerColor initColor, int initHomePos, int initStartPos, int initEndpos, bool isAI) { Color = initColor; Turns = 0; IsPlayerTurn = false; StartPos = initStartPos; HomePos = initHomePos; Endpos = initEndpos; IsComputer = isAI; }
private void initialize(int[] gameBoard, Dice dice, int whiteCheckersOnBar, int whiteCheckersBoreOff, int blackCheckersOnBar, int blackCheckersBoreOff, CheckerColor playerToMove) { this.turnColor = playerToMove; this.dice = dice; recalculateMoves(); this.CurrentTurn = new Turn(turnColor, new List <Move>(), new List <int>(movesLeft)); this.currentGameBoardState = new GameBoardState(gameBoard, whiteCheckersOnBar, whiteCheckersBoreOff, blackCheckersOnBar, blackCheckersBoreOff); }
public static void UpdateWeights(GameBoardState st, GameBoardState st1, CheckerColor c) { color = c; UpdateF(st); DefineEligibilityTraces(st); ParameterUpdate(st, st1); if (double.IsNaN(EligibilityTraces[3])) { throw new Exception(); } }
public Triangle(int numOfCheckers, CheckerColor color) { NumOfCheckers = numOfCheckers; CheckersColor = color; }
public RedPlayer(string name, CheckerColor playerColor) : base(name, playerColor) { }
public Player(string name, CheckerColor color) { Name = name; PlayerColor = color; }