Beispiel #1
0
        public void SaveGame(Pieces pieceFrom, int x, int y, string enemy)
        {
            sw = new StreamWriter(filename, true);

            sw.WriteLine(pieceFrom.ToString() + "," + pieceFrom.Team + "," + pieceFrom.X + "," + pieceFrom.Y + "," + x + "," + y + "," + enemy);

            sw.Close();
        }
Beispiel #2
0
        // Ellenfél összes bábuját megnézzük
        public List <Pieces> IsNotChecked(Chess c, bool turn)
        {
            opponentSteps.Clear();
            List <Pieces> Attackers = new List <Pieces>();
            int           j         = 0;

            for (int i = 0; i < c.pieces.GetLength(0); i++)
            {
                for (int k = 0; k < c.pieces.GetLength(1); k++)
                {
                    if (!(c.pieces[i, k] is null))
                    {
                        if (c.pieces[i, k].Team == 'B' && turn)
                        {
                            if (pieces[i, k] is Pawn)
                            {
                                if (i + 1 < 8 && k + 1 < 8)
                                {
                                    Attackers.Add(new Pawn(i + 1, k + 1, pieces[i, k].Team));
                                }
                                if (i + 1 < 8 && k - 1 >= 0)
                                {
                                    Attackers.Add(new Pawn(i + 1, k - 1, pieces[i, k].Team));
                                }
                            }
                            else
                            {
                                Attackers = c.pieces[i, k].Move(i, k, c);
                            }
                            for (j = 0; j < Attackers.Count; j++)
                            {
                                if (c.pieces[Attackers[j].X, Attackers[j].Y] is King && c.pieces[Attackers[j].X, Attackers[j].Y].Team == 'W')
                                {
                                    if (Attackers[j] is Pawn)
                                    {
                                        Attacker = new Pawn(i, k, Attackers[j].Team);
                                    }
                                    else if (Attackers[j] is Rook)
                                    {
                                        Attacker = new Rook(i, k, Attackers[j].Team);
                                    }
                                    else if (Attackers[j] is Knight)
                                    {
                                        Attacker = new Knight(i, k, Attackers[j].Team);
                                    }
                                    else if (Attackers[j] is Bishop)
                                    {
                                        Attacker = new Bishop(i, k, Attackers[j].Team);
                                    }
                                    else if (Attackers[j] is Queen)
                                    {
                                        Attacker = new Queen(i, k, Attackers[j].Team);
                                    }
                                }
                                if (Attackers[j] is Rook)
                                {
                                    opponentSteps.Add(new Rook(Attackers[j].X, Attackers[j].Y, Attackers[j].Team));
                                }
                                else if (Attackers[j] is Knight)
                                {
                                    opponentSteps.Add(new Knight(Attackers[j].X, Attackers[j].Y, Attackers[j].Team));
                                }
                                else if (Attackers[j] is Bishop)
                                {
                                    opponentSteps.Add(new Bishop(Attackers[j].X, Attackers[j].Y, Attackers[j].Team));
                                }
                                else if (Attackers[j] is Queen)
                                {
                                    opponentSteps.Add(new Queen(Attackers[j].X, Attackers[j].Y, Attackers[j].Team));
                                }
                                else if (Attackers[j] is King)
                                {
                                    opponentSteps.Add(new King(Attackers[j].X, Attackers[j].Y, Attackers[j].Team));
                                }
                                else if (Attackers[j] is Pawn)
                                {
                                    opponentSteps.Add(new Pawn(Attackers[j].X, Attackers[j].Y, Attackers[j].Team));
                                }
                            }
                        }
                        else if (c.pieces[i, k].Team == 'W' && !turn)
                        {
                            if (pieces[i, k] is Pawn)
                            {
                                if (i - 1 >= 0 && k + 1 < 8)
                                {
                                    Attackers.Add(new Pawn(i - 1, k + 1, pieces[i, k].Team));
                                }
                                if (i - 1 >= 0 && k - 1 >= 0)
                                {
                                    Attackers.Add(new Pawn(i - 1, k - 1, pieces[i, k].Team));
                                }
                            }
                            else
                            {
                                Attackers = c.pieces[i, k].Move(i, k, c);
                            }

                            for (j = 0; j < Attackers.Count; j++)
                            {
                                if (c.pieces[Attackers[j].X, Attackers[j].Y] is King && c.pieces[Attackers[j].X, Attackers[j].Y].Team == 'B')
                                {
                                    if (Attackers[j] is Pawn)
                                    {
                                        Attacker = new Pawn(i, k, Attackers[j].Team);
                                    }
                                    else if (Attackers[j] is Rook)
                                    {
                                        Attacker = new Rook(i, k, Attackers[j].Team);
                                    }
                                    else if (Attackers[j] is Knight)
                                    {
                                        Attacker = new Knight(i, k, Attackers[j].Team);
                                    }
                                    else if (Attackers[j] is Bishop)
                                    {
                                        Attacker = new Bishop(i, k, Attackers[j].Team);
                                    }
                                    else if (Attackers[j] is Queen)
                                    {
                                        Attacker = new Queen(i, k, Attackers[j].Team);
                                    }
                                }
                                if (Attackers[j] is Pawn)
                                {
                                    opponentSteps.Add(new Pawn(Attackers[j].X, Attackers[j].Y, Attackers[j].Team));
                                }
                                else if (Attackers[j] is Rook)
                                {
                                    opponentSteps.Add(new Rook(Attackers[j].X, Attackers[j].Y, Attackers[j].Team));
                                }
                                else if (Attackers[j] is Knight)
                                {
                                    opponentSteps.Add(new Knight(Attackers[j].X, Attackers[j].Y, Attackers[j].Team));
                                }
                                else if (Attackers[j] is Bishop)
                                {
                                    opponentSteps.Add(new Bishop(Attackers[j].X, Attackers[j].Y, Attackers[j].Team));
                                }
                                else if (Attackers[j] is Queen)
                                {
                                    opponentSteps.Add(new Queen(Attackers[j].X, Attackers[j].Y, Attackers[j].Team));
                                }
                                else if (Attackers[j] is King)
                                {
                                    opponentSteps.Add(new King(Attackers[j].X, Attackers[j].Y, Attackers[j].Team));
                                }
                            }
                        }
                    }
                }
            }
            return(opponentSteps);
        }