示例#1
0
        private void checkIfGameOver()
        {
            int sizeOfBlackPossibleMoves = 0;
            int sizeOfWhitePossibleMoves = 0;

            for (int y = 0; y < this.r_boardSize; y++)
            {
                for (int x = 0; x < this.r_boardSize; x++)
                {
                    Point            p = new Point(x, y);
                    DamkaPieces.Type t = this.GetPieceByIndex(p);
                    int count          = this.GetLandingOptions(p).Count;

                    if (DamkaPieces.GetKing(t) != DamkaPieces.Type.BlackKing)
                    {
                        sizeOfBlackPossibleMoves += count;
                    }
                    else if (DamkaPieces.GetKing(t) != DamkaPieces.Type.WhiteKing)
                    {
                        sizeOfWhitePossibleMoves += count;
                    }
                }
            }

            if (sizeOfBlackPossibleMoves == 0)
            {
                this.IsGameOver = true;
                this.Winner     = this.r_player2;
            }
            else if (sizeOfWhitePossibleMoves == 0)
            {
                this.IsGameOver = true;
                this.Winner     = this.r_player1;
            }
        }
示例#2
0
        private void switchPieces(Point i_index1, Point i_index2)
        {
            DamkaPieces.Type atIndex1 = this.GetPieceByIndex(i_index1);
            DamkaPieces.Type atIndex2 = this.GetPieceByIndex(i_index2);

            this.placePieceAt(i_index1, atIndex2);
            this.placePieceAt(i_index2, atIndex1);
        }
示例#3
0
        private void checkIfKingged(Point i_index)
        {
            DamkaPieces.Type type = this.GetPieceByIndex(i_index);
            bool             hasReachedOtherSide = this.isSimplePieceOnOtherSide(i_index, type);

            if (hasReachedOtherSide)
            {
                this.placePieceAt(i_index, DamkaPieces.GetKing(type));
            }
        }
示例#4
0
            public void SelfReset()
            {
                DamkaPieces.Type type = s_gameEngine.GetPieceByIndex(this.Index);
                this.Enabled = type != DamkaPieces.Type.None;
                this.Text    = DamkaPieces.GetAdvancedType(type);
                this.Type    = type;
                this.DimButton();

                // Enable only current player.
                bool isSameType = DamkaPieces.IsSameType(s_gameEngine.GetPieceByIndex(this.Index), s_gameEngine.CurrentPlayer.PlayerType);

                this.Enabled = isSameType;
            }
示例#5
0
        private bool isSimplePieceOnOtherSide(Point i_index, DamkaPieces.Type i_type)
        {
            bool result = false;

            if (i_type == DamkaPieces.Type.BlackSimple && i_index.Y == this.r_boardSize - 1)
            {
                result = true;
            }
            else if (i_type == DamkaPieces.Type.WhiteSimple && i_index.Y == 0)
            {
                result = true;
            }

            return(result);
        }
示例#6
0
        private void checkIfEaten(Point i_index0, Point i_index1)
        {
            int howManySkipped = 0;

            int adder  = (i_index1.X - i_index0.X > 0) ? -1 : 1;
            int deltaY = i_index0.Y - i_index1.Y;
            int deltaX = i_index0.X - i_index1.X;
            int m      = deltaY / deltaX;

            int xLow   = (i_index0.X < i_index1.X) ? i_index0.X : i_index1.X;
            int xHigh  = (xLow == i_index1.X) ? i_index0.X : i_index1.X;
            int yOfLow = (xLow == i_index0.X) ? i_index0.Y : i_index1.Y;

            for (int x = i_index1.X + adder; x >= xLow && x <= xHigh; x = x + adder)
            {
                int y = m * (x - xLow) + yOfLow;
                DamkaPieces.Type tmp = this.GetPieceByIndex(new Point(x, y));
                if (DamkaPieces.IsEnemyType(tmp, this.GetPieceByIndex(i_index1)))
                {
                    if (this.isSkippableIndex(i_index0, i_index1))
                    {
                        howManySkipped++;
                    }
                }
            }

            if (howManySkipped == 1)
            {
                for (int x = i_index1.X + adder; x >= xLow && x <= xHigh; x = x + adder)
                {
                    int              y   = m * (x - xLow) + yOfLow;
                    Point            p   = new Point(x, y);
                    DamkaPieces.Type tmp = this.GetPieceByIndex(p);
                    if (DamkaPieces.IsEnemyType(tmp, this.GetPieceByIndex(i_index1)))
                    {
                        if (this.isSkippableIndex(i_index0, i_index1))
                        {
                            this.placePieceAt(p, DamkaPieces.Type.None);
                        }
                    }
                }
            }
        }
示例#7
0
        private bool isIndexAbstractedByEnemy(Point i_destination, Point i_origin)
        {
            int adder  = (i_origin.X - i_destination.X > 0) ? -1 : 1;
            int deltaY = i_destination.Y - i_origin.Y;
            int deltaX = i_destination.X - i_origin.X;
            int m      = deltaY / deltaX;

            int xLow   = (i_destination.X < i_origin.X) ? i_destination.X : i_origin.X;
            int xHigh  = (xLow == i_origin.X) ? i_destination.X : i_origin.X;
            int yOfLow = (xLow == i_destination.X) ? i_destination.Y : i_origin.Y;

            int distance = 0;

            // count how many enemies between the points.
            int numberOfEnemiesInRange = 0;

            for (int x = i_origin.X + adder; x >= xLow && x <= xHigh; x = x + adder)
            {
                distance++;
                int y = m * (x - xLow) + yOfLow;

                DamkaPieces.Type tmp = this.GetPieceByIndex(new Point(x, y));
                if (DamkaPieces.IsEnemyType(tmp, this.GetPieceByIndex(i_origin)))
                {
                    numberOfEnemiesInRange++;
                }
            }

            bool isKing = DamkaPieces.isKing(this.GetPieceByIndex(i_origin));
            bool result = false;

            if (isKing && numberOfEnemiesInRange == 1)
            {
                result = false;
            }
            else if (distance == 1 && numberOfEnemiesInRange == 1)
            {
                result = true;
            }

            return(result);
        }
示例#8
0
        private bool isIndexAbstractedByOtherPiece(Point i_destination, Point i_origin)
        {
            int adder  = (i_origin.X - i_destination.X > 0) ? -1 : 1;
            int deltaY = i_destination.Y - i_origin.Y;
            int deltaX = i_destination.X - i_origin.X;
            int m      = deltaY / deltaX;

            int xLow   = (i_destination.X < i_origin.X) ? i_destination.X : i_origin.X;
            int xHigh  = (xLow == i_origin.X) ? i_destination.X : i_origin.X;
            int yOfLow = (xLow == i_destination.X) ? i_destination.Y : i_origin.Y;

            for (int x = i_origin.X + adder; x >= xLow && x <= xHigh; x += adder)
            {
                int y = m * (x - xLow) + yOfLow;
                DamkaPieces.Type tmp = this.GetPieceByIndex(new Point(x, y));
                if (DamkaPieces.IsSameType(tmp, this.GetPieceByIndex(i_origin)))
                {
                    return(true);
                }
            }
            return(false);
        }
示例#9
0
 private void placePieceAt(Point i_index, DamkaPieces.Type i_type)
 {
     this.Board[i_index.X, i_index.Y] = i_type;
 }
示例#10
0
 public PlayerMove(Point p0, Point p1, DamkaPieces.Type type)
 {
     this.From = p0;
     this.To   = p1;
     this.Type = type;
 }
示例#11
0
 public Player(string i_playerName, DamkaPieces.Type i_playerType)
 {
     this.Name           = i_playerName;
     this.PlayerType     = i_playerType;
     this.m_movesHistory = new LinkedList <PlayerMove>();
 }