예제 #1
0
파일: Pawn.cs 프로젝트: Mittens2/Chess
 public void getmoves(Board x, int y)
 {
     //Finds moves available to the pice based on what pices it is.
     int firstmove;
     if (y == 1)
     {
         firstmove = 1;
     }
     else
     {
         firstmove = 6;
     }
     if(x.numy == firstmove && (x.board[x.numx, x.numy + (2 * y)] == 0))
     {
         x.moves[x.a] = new Point(x.numx, x.numy + (2 * y));
         x.a++;
     }
     if ((x.numx < 7) && ((x.board[x.numx + 1, x.numy + (1 * y)] * y) > 0))
     {
         x.moves[x.a] = new Point(x.numx + 1, x.numy + (1 * y));
         x.a++;
     }
     if ((x.numx > 0) && ((x.board[x.numx - 1, x.numy + (1 * y)] * y) > 0))
     {
         x.moves[x.a] = new Point(x.numx - 1, x.numy + (1 * y));
         x.a++;
     }
     if (x.board[x.numx, x.numy + (1 * y)] == 0)
     {
         x.moves[x.a] = new Point(x.numx, x.numy + (1 * y));
         x.a++;
     }
 }
예제 #2
0
파일: Knight.cs 프로젝트: Mittens2/Chess
 public void getmoves(Board x, int y)
 {
     int nx = x.numx;
     int ny = x.numy;
     if (nx + 2 < 8)
     {
         if (ny + 1 < 8 && x.board[nx + 2, ny + 1] * y < 1)
         {
             x.moves[x.a] = new Point(nx + 2, ny + 1);
             x.a++;
         }
         if (ny - 1 > -1 && x.board[nx + 2, ny - 1] * y < 1)
         {
             x.moves[x.a] = new Point(nx + 2, ny - 1);
             x.a++;
         }
     }
     if (ny + 2 < 8)
     {
         if (nx + 1 < 8 && x.board[nx + 1, ny + 2] * y < 1)
         {
             x.moves[x.a] = new Point(nx + 1, ny + 2);
             x.a++;
         }
         if (nx - 1 > -1 && x.board[nx - 1, ny + 2] * y < 1)
         {
             x.moves[x.a] = new Point(nx - 1, ny + 2);
             x.a++;
         }
     }
     if (nx - 2 > -1)
     {
         if (ny + 1 < 8 && x.board[nx - 2, ny + 1] * y < 1)
         {
             x.moves[x.a] = new Point(nx - 2, ny + 1);
             x.a++;
         }
         if (ny - 1 > -1 && x.board[nx - 2, ny - 1] * y < 1)
         {
             x.moves[x.a] = new Point(nx - 2, ny - 1);
             x.a++;
         }
     }
     if (ny - 2 > -1)
     {
         if (nx + 1 < 8 && x.board[nx + 1, ny - 2] * y < 1)
         {
             x.moves[x.a] = new Point(nx + 1, ny - 2);
             x.a++;
         }
         if (nx - 1 > -1 && x.board[nx - 1, ny - 2] * y < 1)
         {
             x.moves[x.a] = new Point(nx - 1, ny - 2);
             x.a++;
         }
     }
 }
예제 #3
0
파일: Pawn.cs 프로젝트: Mittens2/Chess
 public void move(Pawn c, Point s, Board x, int a)
 {
     /*moves peice if it does not put own king in check, or if the
      * program is simulating a checkmate. If program is simulating a checkmate
      program will not "eat" other pieces (hnece the skip method).*/
     int t = x.board[s.X, s.Y];
     Boolean skip = true;
     x.cannotmove = false;
     int numx2 = x.numx;
     int numy2 = x.numy;
     Point unmove = new Point(c.coords.X, c.coords.Y);
     if (x.board[s.X, s.Y] != 0 && x.board[s.X, s.Y] * a < 0)
     {
         if (x.checkmachecker)
         {
             skip = false;
         }
         else
         {
             x.eat(s, x);
         }
     }
     c.coords = new Point(x.Grid[s.X, s.Y].X + 23, x.Grid[s.X, s.Y].Y+ 10);
     x.board[s.X, s.Y] = a;
     x.turner = x.turner * - 1;
     Boolean kingcheck = false;
     if (skip)
     {
         if (x.turncount % 2 == 0)
         {
             kingcheck = x.checkcheck(x, x.whiteking);
         }
         else
         {
             kingcheck = x.checkcheck(x, x.blacking);
         }
     }
     if (kingcheck || x.checkmachecker)
     {
         c.coords = new Point(unmove.X, unmove.Y);
         x.board[s.X, s.Y] = t;
         x.board[numx2, numy2] = a;
         if (kingcheck)
         {
             x.cannotmove = true;
         }
     }
     x.numx = numx2;
     x.numy = numy2;
     x.turner = x.turner * -1;
 }
예제 #4
0
파일: Knight.cs 프로젝트: Mittens2/Chess
 public void move(Knight c, Point s, Board x, int a)
 {
     int t = x.board[s.X, s.Y];
     Boolean skip = true;
     x.cannotmove = false;
     int numx2 = x.numx;
     int numy2 = x.numy;
     Point unmove = new Point(c.coords.X, c.coords.Y);
     if (x.board[s.X, s.Y] != 0 && x.board[s.X, s.Y] * a < 0)
     {
         if (x.checkmachecker)
         {
             skip = false;
         }
         else
         {
             x.eat(s, x);
         }
     }
     c.coords = new Point(x.Grid[s.X, s.Y].X + 23, x.Grid[s.X, s.Y].Y + 6);
     x.board[s.X, s.Y] = a;
     Boolean kingcheck = false;
     x.turner = x.turner * -1;
     if (skip)
     {
         if (x.turncount % 2 == 0)
         {
             kingcheck = x.checkcheck(x, x.whiteking);
         }
         else
         {
             kingcheck = x.checkcheck(x, x.blacking);
         }
     }
     if (kingcheck || x.checkmachecker)
     {
         c.coords = new Point(unmove.X, unmove.Y);
         x.board[s.X, s.Y] = t;
         x.board[numx2, numy2] = a;
         if (kingcheck)
         {
             x.cannotmove = true;
         }
     }
     x.numx = numx2;
     x.numy = numy2;
     x.turner = x.turner * -1;
 }
예제 #5
0
파일: Knight.cs 프로젝트: Mittens2/Chess
 public void geteaten(Knight c, Board x, int a)
 {
     if (a == 1)
     {
         if (x.count == 4)
         {
             x.count = 0;
             x.n += 70;
         }
         c.coords = new Point(x.n, x.m + (70 * x.count));
         x.count++;
     }
     else
     {
         if (x.count2 == 4)
         {
             x.count2 = 0;
             x.o += 70;
         }
         c.coords = new Point(x.o, x.p + (70 * x.count2));
         x.count2++;
     }
 }
예제 #6
0
파일: Rooks.cs 프로젝트: Mittens2/Chess
 public void getmoves(Board x, int y)
 {
     int nx = x.numx;
     int ny = x.numy;
     for (int i = nx + 1; i < 8; i++)
     {
         if (x.board[i, ny] != 0)
         {
             if (x.board[i, ny] * y < 0)
             {
                 x.moves[x.a] = new Point(i, ny);
                 x.a++;
             }
             break;
         }
         x.moves[x.a] = new Point(i, ny);
         x.a++;
     }
     for (int i = nx - 1; i > -1; i--)
     {
         if (x.board[i, ny] != 0)
         {
             if (x.board[i, ny] * y < 0)
             {
                 x.moves[x.a] = new Point(i, ny);
                 x.a++;
             }
             break;
         }
         x.moves[x.a] = new Point(i, ny);
         x.a++;
     }
     for (int i = ny + 1; i < 8; i++)
     {
         if (x.board[nx, i] != 0)
         {
             if (x.board[nx, i] * y < 0)
             {
                 x.moves[x.a] = new Point(nx, i);
                 x.a++;
             }
             break;
         }
         x.moves[x.a] = new Point(nx, i);
         x.a++;
     }
     for (int i = ny - 1; i > -1; i--)
     {
         if (x.board[nx, i] != 0)
         {
             if (x.board[nx, i] * y < 0)
             {
                 x.moves[x.a] = new Point(nx, i);
                 x.a++;
             }
             break;
         }
         x.moves[x.a] = new Point(nx, i);
         x.a++;
     }
 }
예제 #7
0
파일: Queen.cs 프로젝트: Mittens2/Chess
 public void getmoves(Board x, int y)
 {
     int nx = x.numx;
     int ny = x.numy;
     for (int i = nx + 1; i < 8; i++)
     {
         if (x.board[i, ny] != 0)
         {
             if (x.board[i, ny] * y < 0)
             {
                 x.moves[x.a] = new Point(i, ny);
                 x.a++;
             }
             break;
         }
         x.moves[x.a] = new Point(i, ny);
         x.a++;
     }
     for (int i = nx - 1; i > -1; i--)
     {
         if (x.board[i, ny] != 0)
         {
             if (x.board[i, ny] * y < 0)
             {
                 x.moves[x.a] = new Point(i, ny);
                 x.a++;
             }
             break;
         }
         x.moves[x.a] = new Point(i, ny);
         x.a++;
     }
     for (int i = ny + 1; i < 8; i++)
     {
         if (x.board[nx, i] != 0)
         {
             if (x.board[nx, i] * y < 0)
             {
                 x.moves[x.a] = new Point(nx, i);
                 x.a++;
             }
             break;
         }
         x.moves[x.a] = new Point(nx, i);
         x.a++;
     }
     for (int i = ny - 1; i > -1; i--)
     {
         if (x.board[nx, i] != 0)
         {
             if (x.board[nx, i] * y < 0)
             {
                 x.moves[x.a] = new Point(nx, i);
                 x.a++;
             }
             break;
         }
         x.moves[x.a] = new Point(nx, i);
         x.a++;
     }
     nx = x.numx + 1;
     ny = x.numy - 1;
     while (nx < 8 && ny > -1)
     {
         if (x.board[nx, ny] != 0)
         {
             if (x.board[nx, ny] * y < 0)
             {
                 x.moves[x.a] = new Point(nx, ny);
                 x.a++;
             }
             break;
         }
         x.moves[x.a] = new Point(nx, ny);
         nx++;
         ny--;
         x.a++;
     }
     nx = x.numx - 1;
     ny = x.numy - 1;
     while (nx > -1 && ny > -1)
     {
         if (x.board[nx, ny] != 0)
         {
             if (x.board[nx, ny] * y < 0)
             {
                 x.moves[x.a] = new Point(nx, ny);
                 x.a++;
             }
             break;
         }
         x.moves[x.a] = new Point(nx, ny);
         nx--;
         ny--;
         x.a++;
     }
     nx = x.numx - 1;
     ny = x.numy + 1;
     while (nx > -1 && ny < 8)
     {
         if (x.board[nx, ny] != 0)
         {
             if (x.board[nx, ny] * y < 0)
             {
                 x.moves[x.a] = new Point(nx, ny);
                 x.a++;
             }
             break;
         }
         x.moves[x.a] = new Point(nx, ny);
         ny++;
         nx--;
         x.a++;
     }
     nx = x.numx + 1;
     ny = x.numy + 1;
     while (nx < 8 && ny < 8)
     {
         if (x.board[nx, ny] != 0)
         {
             if (x.board[nx, ny] * y < 0)
             {
                 x.moves[x.a] = new Point(nx, ny);
                 x.a++;
             }
             break;
         }
         x.moves[x.a] = new Point(nx, ny);
         nx++;
         ny++;
         x.a++;
     }
 }
예제 #8
0
파일: Pawn.cs 프로젝트: Mittens2/Chess
        public void geteaten(Pawn c, Board x, int a)
        {
            /*Relocates pice out of the board if it is eaten (notice King does ot have a geteaten
             * cabability, as once it is in checkmate the gmae ends.*/
            if (a == 1)
            {
                if (x.count == 4)
                {
                    x.count = 0;
                    x.n += 70;
                }
                c.coords = new Point(x.n, x.m + (70 * x.count));
                x.count++;
            }
            else
            {
                if (x.count2 == 4)
                {
                    x.count2 = 0;
                    x.o += 70;
                }
                c.coords = new Point(x.o, x.p + (70 * x.count2));
                x.count2++;
            }

        }
예제 #9
0
파일: Board.cs 프로젝트: Mittens2/Chess
 public Boolean checkmablackchecker(Board chess)
 {
     Boolean br = false;
     checkmachecker = true;
     turner = turner * -1;
     turncount++;
     Rectangle pop = new Rectangle();
     //See checkmawhitechecker, apply same logic except for black king.
     for (int i = 0; i < 8; i++)
     {
         if (br)
         {
             break;
         }
         for (int j = 0; j < 8; j++)
         {
             a = 0;
             if (br)
             {
                 break;
             }
             if (board[j, i] > 0)
             {
                 pop = Grid[j, i];
                 numx = j;
                 numy = i;
                 findpeice(pop, chess);
                 for (int w = 0; w < chess.a; w++)
                 {
                     move = moves[w];
                     determinepiece(chess);
                     if (cannotmove == false)
                     {
                         count++;
                         br = true;
                         break;
                     }
                 }
             }
         }
     }
     turncount--;
     turner = turner * -1;
     checkmachecker = false;
     if (count == 0)
     {
         checkmablack = true;
         return true;
     }
     return false;
 }
예제 #10
0
 public Board getBoard()
 {
     board = new Board();
     return(board);
 }
예제 #11
0
파일: Board.cs 프로젝트: Mittens2/Chess
 public Boolean checkmatewhitechecker(Board chess)
 {
     Boolean br = false;
     checkmachecker = true;
     turner = turner * -1;
     turncount++;
     Rectangle pop = new Rectangle();
     /*Checks whether the white king is in checkmate by going through a loop
      * which finds all of a piece's move, simulates all of the moves and sees
      * if the king is still in check. If every move shows that the kings is
      * still in check, then the game is over, the king is in checkmate*/
     for (int i = 0; i < 8; i++)
     {
         if (br)
         {
             break;
         }
         for (int j = 0; j < 8; j++)
         {
             a = 0;
             if (br)
             {
                 break;
             }
             if (board[j, i] < 0)
             {
                 pop = Grid[j, i];
                 numx = j;
                 numy = i;
                 findpeice(pop, chess);
                 for (int w = 0; w < a; w++)
                 {
                     move = moves[w];
                     determinepiece(chess);
                     if(cannotmove == false)
                     {
                         count++;
                         br = true;
                         break;
                     }
                 }
             }
         }
     }
     br = false;
     turncount--;
     turner = turner * -1;
     checkmachecker = false;
     if (count == 0)
     {
         checkmawhite = true;
         return true;
     }
     return false;
 }
예제 #12
0
파일: Board.cs 프로젝트: Mittens2/Chess
 public Boolean checkcheck(Board x, King c)
 {
     int p = 100;
     int q = 40;
     Point [] checkpossibs = new Point [500];
     x.a = 0;
     /*Checks whether the king is in check, by checking all of the oppossing
      * player's moves and seeing whether they can eat the king*/
      for (int i = 0; i < 8; i++)
     {
         for (int j = 0; j < 8; j++)
         {
             x.piecelocate(p, q);
             if (board[x.numx, x.numy] != 0)
             {
                 checkpossibs = x.findpeice(x.Grid[x.numx, x.numy], x);
             }
             q+= 80;
         }
         q = 40;
         p += 80;
     }
         for(int i = 0; i < x.a; i++)
         {
             if (Grid[checkpossibs[i].X, checkpossibs[i].Y].Contains(c.getcoords()))
             {
                 x.a = 0;
                 return true;
             }
         }
         x.a = 0;
         return false;
     
 }
예제 #13
0
파일: Board.cs 프로젝트: Mittens2/Chess
        public void eat(Point a, Board c)
        {
            //Goes to a method within each peace which causes them to get eaten.
                    for (int j = 0; j < 8; j++)
                    {
                        if (Grid[a.X, a.Y].Contains(blackpawns[j].getcoords()))
                        {
                            blackpawns[j].geteaten(blackpawns[j], c, 1);
                        }
                        if (Grid[a.X, a.Y].Contains(whitepawns[j].getcoords()))
                        {
                            whitepawns[j].geteaten(whitepawns[j], c, -1);
                        }
                        if (j < 2 && (Grid[a.X, a.Y].Contains(blackrooks[j].getcoords())))
                        {
                            blackrooks[j].geteaten(blackrooks[j], c, 1);
                            break;
                        }
                        if (j < 2 && (Grid[a.X, a.Y].Contains(whiterooks[j].getcoords())))
                        {
                            whiterooks[j].geteaten(whiterooks[j], c, -1);
                            break;
                        }

                        if (j < 2 && (Grid[a.X, a.Y].Contains(blackbishops[j].getcoords())))
                        {
                            blackbishops[j].geteaten(blackbishops[j], c, 1);
                            break;
                        }
                        if (j < 2 && (Grid[a.X, a.Y].Contains(whitebishops[j].getcoords())))
                        {
                            whitebishops[j].geteaten(whitebishops[j], c, -1);
                            break;
                        }
                        if (j < 2 && (Grid[a.X, a.Y].Contains(blacknights[j].getcoords())))
                        {
                            blacknights[j].geteaten(blacknights[j], c, 1);
                            break;
                        }
                        if (j < 2 && (Grid[a.X, a.Y].Contains(whiteknights[j].getcoords())))
                        {
                            whiteknights[j].geteaten(whiteknights[j], c, -1);
                            break;
                        }
                        if (j < 1 && (Grid[a.X, a.Y].Contains(whitequeen.getcoords())))
                        {
                            whitequeen.geteaten(whitequeen, c, -1);
                            break;
                        }
                        if (j < 1 && (Grid[a.X, a.Y].Contains(blackqueen.getcoords())))
                        {
                            blackqueen.geteaten(blackqueen, c, 1);
                            break;
                        }
                }
        }
예제 #14
0
파일: Board.cs 프로젝트: Mittens2/Chess
 public Boolean determinepiece(Board c)
 {
     //Checks for every move.
     for (int i = 0; i < a; i++)
     {
         /*If the move which the user has selected is on of the possible
          * moves, moves the peice accordingly.*/
         if (move == moves[i])
         {
             board[numx, numy] = 0;
             for (int j = 0; j < 8; j++)
             {
                 if (Grid[numx, numy].Contains(blackpawns[j].getcoords()))
                 {
                     blackpawns[j].move(blackpawns[j], move, c, 1);
                 }
                 if (Grid[numx, numy].Contains(whitepawns[j].getcoords()))
                 {
                     whitepawns[j].move(whitepawns[j], move, c, -1);
                 }
                 if (j < 2 && (Grid[numx, numy].Contains(blackrooks[j].getcoords())))
                 {
                     blackrooks[j].move(blackrooks[j], move, c, 1);
                 }
                 if (j < 2 && (Grid[numx, numy].Contains(whiterooks[j].getcoords())))
                 {
                     whiterooks[j].move(whiterooks[j], move, c, -1);
                 }
                 if (j < 2 && (Grid[numx, numy].Contains(blackbishops[j].getcoords())))
                 {
                     blackbishops[j].move(blackbishops[j], move, c, 1);
                     break;
                 }
                 if (j < 2 && (Grid[numx, numy].Contains(whitebishops[j].getcoords())))
                 {
                     whitebishops[j].move(whitebishops[j], move, c, -1);
                     break;
                 }
                 if (j < 2 && (Grid[numx, numy].Contains(blacknights[j].getcoords())))
                 {
                     blacknights[j].move(blacknights[j], move, c, 1);
                     break;
                 }
                 if (j < 2 && (Grid[numx, numy].Contains(whiteknights[j].getcoords())))
                 {
                     whiteknights[j].move(whiteknights[j], move, c, -1);
                     break;
                 }
                 if (j < 1 && (Grid[numx, numy].Contains(whitequeen.getcoords())))
                 {
                     whitequeen.move(whitequeen, move, c, -1);
                     break;
                 }
                 if (j < 1 && (Grid[numx, numy].Contains(blackqueen.getcoords())))
                 {
                     blackqueen.move(blackqueen, move, c, 1);
                     break;
                 }
                 if (j < 1 && (Grid[numx, numy].Contains(blacking.getcoords())))
                 {
                     blacking.move(blacking, move, c, 6);
                     break;
                 }
                 if (j < 1 && (Grid[numx, numy].Contains(whiteking.getcoords())))
                 {
                     whiteking.move(whiteking, move, c, -6);
                     break;
                 }
             }
             return true;
         }
     }
     return false;
 }
예제 #15
0
파일: Board.cs 프로젝트: Mittens2/Chess
 public Point[] findpeice(Rectangle a, Board x)
 {
     //Gets the possible moves for the selected peice.
     for (int i = 0; i < 8; i++)
     {
         if (a.Contains(blackpawns[i].getcoords()))
         {
             blackpawns[i].getmoves(x, -1);
         }
         if (a.Contains(whitepawns[i].getcoords()))
         {
             whitepawns[i].getmoves(x, 1);
         }
         if (i < 2 && (a.Contains(blackrooks[i].getcoords())))
         {
             blackrooks[i].getmoves(x, 1);
             break;
         }
         if (i < 2 && (a.Contains(whiterooks[i].getcoords())))
         {
             whiterooks[i].getmoves(x, -1);
             break;
         }
         if (i < 2 && (a.Contains(blackbishops[i].getcoords())))
         {
             blackbishops[i].getmoves(x, 1);
             break;
         }
         if (i < 2 && (a.Contains(whitebishops[i].getcoords())))
         {
            whitebishops[i].getmoves(x, -1);
             break;
         }
         if (i < 2 && (a.Contains(blacknights[i].getcoords())))
         {
             blacknights[i].getmoves(x, 1);
             break;
         }
         if (i < 2 && (a.Contains(whiteknights[i].getcoords())))
         {
             whiteknights[i].getmoves(x, -1);
             break;
         }
         if (i < 1 && (a.Contains(whitequeen.getcoords())))
         {
             whitequeen.getmoves(x, -1);
             break;
         }
         if (i < 1 && (a.Contains(blackqueen.getcoords())))
         {
             blackqueen.getmoves(x, 1);
             break;
         }
         if (i < 1 && (a.Contains(blacking.getcoords())))
         {
             blacking.getmoves(x, 1);
             break;
         }
         if (i < 1 && (a.Contains(whiteking.getcoords())))
         {
             whiteking.getmoves(x, -1);
             break;
         }
     }
     return moves;
 }