예제 #1
0
        public static Dictionary <int, Dictionary <int, ChessPiece> > GetScenario(Move testMove)
        {
            var scenario = HelperMaths.DeepClone(Layout);

            scenario[testMove.Destination.Item1][testMove.Destination.Item2] = scenario[testMove.Origin.Item1][testMove.Origin.Item2];
            scenario[testMove.Origin.Item1][testMove.Origin.Item2]           = null;

            return(scenario);
        }
예제 #2
0
        public static bool HorizontalThreatCheck(int kingX, int kingY, Dictionary <int, Dictionary <int, ChessPiece> > scenario, PieceColor enemy)
        {
            for (int i = 1; i <= 8; i++)
            {
                if (HelperMaths.IsInRange(kingY + i, 0, 7))
                {
                    if (scenario[kingX][kingY + i] != null)
                    {
                        if (scenario[kingX][kingY + i].ToString() == enemy.ToString() + PieceType.Rook.ToString() ||
                            scenario[kingX][kingY + i].ToString() == enemy.ToString() + PieceType.Queen.ToString())
                        {
                            return(true);
                        }
                        else
                        {
                            break;
                        }
                    }
                }
                else
                {
                    break;
                }
            }

            for (int i = 1; i <= 8; i++)
            {
                if (HelperMaths.IsInRange(kingY - i, 0, 7))
                {
                    if (scenario[kingX][kingY - i] != null)
                    {
                        if (scenario[kingX][kingY - i].ToString() == enemy.ToString() + PieceType.Rook.ToString() ||
                            scenario[kingX][kingY - i].ToString() == enemy.ToString() + PieceType.Queen.ToString())
                        {
                            return(true);
                        }
                        else
                        {
                            break;
                        }
                    }
                }
                else
                {
                    break;
                }
            }

            return(false);
        }
예제 #3
0
        //-----------------------------------------------------------------

        // King check functions

        //-----------------------------------------------------------------

        public static bool EnemyPawnCheck(int kingX, int kingY, Dictionary <int, Dictionary <int, ChessPiece> > scenario, PieceColor enemy)
        {
            if (enemy == PieceColor.Black)
            {
                if (HelperMaths.IsInRange(kingX - 1, 0, 7) && HelperMaths.IsInRange(kingY - 1, 0, 7))
                {
                    if (scenario[kingX - 1][kingY - 1]?.ToString() == enemy.ToString() + "Pawn")
                    {
                        return(true);
                    }
                }

                if (HelperMaths.IsInRange(kingX - 1, 0, 7) && HelperMaths.IsInRange(kingY + 1, 0, 7))
                {
                    if (scenario[kingX - 1][kingY + 1]?.ToString() == enemy.ToString() + "Pawn")
                    {
                        return(true);
                    }
                }
            }

            if (enemy == PieceColor.White)
            {
                if (HelperMaths.IsInRange(kingX + 1, 0, 7) && HelperMaths.IsInRange(kingY - 1, 0, 7))
                {
                    if (scenario[kingX + 1][kingY - 1]?.ToString() == enemy.ToString() + "Pawn")
                    {
                        return(true);
                    }
                }

                if (HelperMaths.IsInRange(kingX + 1, 0, 7) && HelperMaths.IsInRange(kingY + 1, 0, 7))
                {
                    if (scenario[kingX + 1][kingY + 1]?.ToString() == enemy.ToString() + "Pawn")
                    {
                        return(true);
                    }
                }
            }
            return(false);
        }
예제 #4
0
        private static bool TestKingChecks(Dictionary <int, Dictionary <int, ChessPiece> > scenario)
        {
            for (int i = 0; i < 8; i++)
            {
                for (int j = 0; j < 8; j++)
                {
                    if (scenario[i][j]?.ToString() == GameState.PlayerTurn.ToString() + "King")
                    {
                        PieceColor enemy = GameState.PlayerTurn == PieceColor.Black ? enemy = PieceColor.White : enemy = PieceColor.Black;

                        if (HelperMaths.EnemyPawnCheck(i, j, scenario, enemy) || HelperMaths.HorizontalThreatCheck(i, j, scenario, enemy) ||
                            HelperMaths.DiagonalThreatCheck(i, j, scenario, enemy) || HelperMaths.VerticalThreatCheck(i, j, scenario, enemy) ||
                            HelperMaths.HorseThreatCheck(i, j, scenario, enemy))
                        {
                            return(true);
                        }
                        return(false);
                    }
                }
            }
            return(false);
        }
예제 #5
0
        public static bool HorseThreatCheck(int kingX, int kingY, Dictionary <int, Dictionary <int, ChessPiece> > scenario, PieceColor enemy)
        {
            if (HelperMaths.IsInRange(kingX - 2, 0, 7) && HelperMaths.IsInRange(kingY - 1, 0, 7))
            {
                if (scenario[kingX - 2][kingY - 1]?.ToString() == enemy.ToString() + "Horseman")
                {
                    return(true);
                }
            }

            if (HelperMaths.IsInRange(kingX - 2, 0, 7) && HelperMaths.IsInRange(kingY + 1, 0, 7))
            {
                if (scenario[kingX - 2][kingY + 1]?.ToString() == enemy.ToString() + "Horseman")
                {
                    return(true);
                }
            }

            if (HelperMaths.IsInRange(kingX + 2, 0, 7) && HelperMaths.IsInRange(kingY - 1, 0, 7))
            {
                if (scenario[kingX + 2][kingY - 1]?.ToString() == enemy.ToString() + "Horseman")
                {
                    return(true);
                }
            }

            if (HelperMaths.IsInRange(kingX + 2, 0, 7) && HelperMaths.IsInRange(kingY + 1, 0, 7))
            {
                if (scenario[kingX + 2][kingY + 1]?.ToString() == enemy.ToString() + "Horseman")
                {
                    return(true);
                }
            }

            //

            if (HelperMaths.IsInRange(kingX + 1, 0, 7) && HelperMaths.IsInRange(kingY + 2, 0, 7))
            {
                if (scenario[kingX + 1][kingY + 2]?.ToString() == enemy.ToString() + "Horseman")
                {
                    return(true);
                }
            }

            if (HelperMaths.IsInRange(kingX - 1, 0, 7) && HelperMaths.IsInRange(kingY + 2, 0, 7))
            {
                if (scenario[kingX - 1][kingY + 2]?.ToString() == enemy.ToString() + "Horseman")
                {
                    return(true);
                }
            }

            if (HelperMaths.IsInRange(kingX + 1, 0, 7) && HelperMaths.IsInRange(kingY - 2, 0, 7))
            {
                if (scenario[kingX + 1][kingY - 2]?.ToString() == enemy.ToString() + "Horseman")
                {
                    return(true);
                }
            }

            if (HelperMaths.IsInRange(kingX - 1, 0, 7) && HelperMaths.IsInRange(kingY - 2, 0, 7))
            {
                if (scenario[kingX - 1][kingY - 2]?.ToString() == enemy.ToString() + "Horseman")
                {
                    return(true);
                }
            }

            return(false);
        }
예제 #6
0
        public static Dictionary <int, Dictionary <int, ChessPiece> > GetGameState()
        {
            var clone = HelperMaths.DeepClone(Layout);

            return(clone);
        }