예제 #1
0
        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();
        }
예제 #2
0
        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);
            }
        }
예제 #3
0
        //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);
        }
예제 #4
0
 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);
 }
예제 #5
0
 public StateChangedEventArgs(BoardPosition boardPosition, Dice dice, CheckerColor checkerColor, Logic logic)
 {
     BoardPosition = boardPosition;
     Dice          = dice;
     CheckerColor  = checkerColor;
     Logic         = logic;
 }
예제 #6
0
        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();
        }
예제 #7
0
 public void RemoveCheckerFromTriangle(int triangleNumber, CheckerColor checkerColor)
 {
     if (checkerColor != Triangles[triangleNumber].CheckersColor)
     {
         Triangles[triangleNumber].NumOfCheckers--;
     }
 }
예제 #8
0
파일: Board.cs 프로젝트: Oreneo/Backgammon
 public void AddCheckerToTriangle(int triangleNumber, CheckerColor checkerColor)
 {
     if (checkerColor != Triangles[triangleNumber].CheckersColor)
     {
         Triangles[triangleNumber].NumOfCheckers++;
     }
 }
예제 #9
0
 public void TurnActiveColorSide()
 {
     if (!_repeatMove)
     {
         _activeCheckerColor = _activeCheckerColor == CheckerColor.WHITE ? CheckerColor.BLACK : CheckerColor.WHITE;
     }
 }
예제 #10
0
 public void AddCheckerToTriangle(int triangleNumber, CheckerColor checkerColor)
 {
     if (checkerColor != Triangles[triangleNumber].CheckersColor)
     {
         Triangles[triangleNumber].NumOfCheckers++;
     }
 }
예제 #11
0
 public void AddNewCheckers(Point p, CheckerColor color, int count)
 {
     for (; count > 0; count--)
     {
         p.Checkers.Push(new Checker(nextCheckerId++, color, p.Position));
     }
 }
예제 #12
0
        // 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);
        }
예제 #13
0
 //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;
     }
 }
예제 #14
0
 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);
 }
예제 #15
0
파일: Board.cs 프로젝트: Oreneo/Backgammon
 public void RemoveCheckerFromTriangle(int triangleNumber, CheckerColor checkerColor)
 {
     if (checkerColor != Triangles[triangleNumber].CheckersColor)
     {
         Triangles[triangleNumber].NumOfCheckers--;
     }
 }
예제 #16
0
        //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);
        }
예제 #17
0
 public void RemoveChecker()
 {
     CheckersAmount--;
     if (CheckersAmount < 1)
     {
         Color = CheckerColor.Empty;
     }
 }
예제 #18
0
파일: Checker.cs 프로젝트: mighty927/mighty
 /// <summary>
 /// Create new checker instance.
 /// </summary>
 public Checker(int id, Square square, CheckerColor color)
 {
     Id             = id;
     Square         = square;
     Color          = color;
     IsSuperChecker = false;
     IsBeat         = false;
 }
예제 #19
0
 internal bool CheckerWasCaptured(CheckerColor playerColor, int to)
 {
     try
     {
         return(Points[to].GetAmount() == 1 && Points[to].GetTopChecker().Color != playerColor);
     }
     catch (ArgumentOutOfRangeException) { return(false); }
 }
예제 #20
0
 private Point GetBearOffPoint(CheckerColor color)
 {
     if (color == White)
     {
         return(WhiteBearOff);
     }
     return(BlackBearOff);
 }
예제 #21
0
 private Point GetOnBarPoint(CheckerColor color)
 {
     if (color == White)
     {
         return(WhiteBar);
     }
     return(BlackBar);
 }
예제 #22
0
 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());
 }
예제 #23
0
 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++;
 }
예제 #24
0
 internal void MakeMove(BackgammonGame model, CheckerColor color)
 {
     if (RemotePlayer == null)
     {
         Instantiate(model, color);
     }
     RemotePlayer.MakeMove();
 }
예제 #25
0
 public Checker(int row, int column, Game game, Image img, CheckerColor color)
 {
     Game   = game;
     Color  = color;
     Row    = row;
     Column = column;
     Image  = img;
 }
예제 #26
0
 public int?GetStartRollNumber(CheckerColor color)
 {
     if (startRollNumbers.TryGetValue(color, out int val))
     {
         return(val);
     }
     return(null);
 }
예제 #27
0
 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;
 }
예제 #28
0
        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);
        }
예제 #29
0
        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());
        }
예제 #30
0
 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;
 }
예제 #31
0
        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);
        }
예제 #32
0
 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();
     }
 }
예제 #33
0
 public Triangle(int numOfCheckers, CheckerColor color)
 {
     NumOfCheckers = numOfCheckers;
     CheckersColor = color;
 }
예제 #34
0
        public RedPlayer(string name, CheckerColor playerColor) : base(name, playerColor) 
        {

        }
예제 #35
0
        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);
            }
        }
예제 #36
0
파일: Player.cs 프로젝트: Oreneo/Backgammon
 public Player(string name, CheckerColor color)
 {
     Name = name;
     PlayerColor = color;
 }