public Game_Universe() { this.White_Player = new Player(Player.Colors.WHITE); // player 1 this.Black_Player = new Player(Player.Colors.BLACK); // player 2 this.board = new Board(); // pull out a board White_Player.initialize_Pieces(ref board); //white puts pieces on board Black_Player.initialize_Pieces(ref board); //black puts pieces on board turnNumber = 1; // first turn }
public override bool moveRules(byte pDestination, Board board) { byte furthest_left, furthest_right, furthest_up, furthest_down; isPieceOnFile(this.Location, out furthest_up, out furthest_down, board); isPieceOnRow(this.Location, out furthest_left, out furthest_right, board); byte mod_value = (byte)(this.Location % 8); if (pDestination % 8 == mod_value) { if (pDestination >= furthest_down && pDestination <= furthest_up) return true; else return false; } else if (pDestination >= furthest_right && pDestination <= furthest_left) { return true; } return false; }
public override bool captureRules(byte pDestination, Board board) { throw new NotImplementedException(); }
public bool isPieceOnRow(byte pLocation, out byte pFurthest_Left, out byte pFurthest_Right, Board board) { // look left and right on the row to see if a piece will cause another piece to not be able to move as far sbyte furthest_left = -1; // furthest value left of location that a piece can move to sbyte furthest_right = -1; // furthest value right of location that a piece can move to sbyte range_to_check_right = (sbyte)((int)pLocation % 8); //will be a value 0-7 giving us a range to check left and right of location sbyte range_to_check_left = (sbyte)(7 - range_to_check_right); if (range_to_check_right == 0) // we are on the right edge of the board { furthest_right = (sbyte)pLocation; for (sbyte i = (sbyte)(pLocation + 1); i <= (sbyte)(pLocation + range_to_check_left); i++) // check as far as the left side of the board { if (board.Squares[i].PieceOn) { furthest_left = (sbyte)(i - pLocation - 1); // number of spots piece can move left of the location tile break; } } if (furthest_left == -1) // no piece to our location's left { pFurthest_Right = (byte)pLocation; // we are on the right edge of the board, can't move right. pFurthest_Left = (byte)(pLocation + 7); // we can move as far left as we want, but not over the edge of the board return false; } else { pFurthest_Right = pLocation; pFurthest_Left = (byte)furthest_left; return true; } } else if (range_to_check_left == 0) { furthest_left = (sbyte)pLocation; for (sbyte i = (sbyte)(pLocation - 1); i >= pLocation - range_to_check_right; i--) // check as far as the right side of the board { if (board.Squares[i].PieceOn) { furthest_right = (sbyte)(pLocation - (pLocation - i - 1)); // number of spots piece can move right of the location tile break; } } if (furthest_right == -1) { pFurthest_Left = pLocation; pFurthest_Right = (byte)(pLocation - 7); return false; } else { pFurthest_Left = pLocation; pFurthest_Right = (byte)furthest_right; return true; } } else // piece is not on left or right edge of board { for (sbyte i = (sbyte)(pLocation - 1); i >= pLocation - range_to_check_right; i--) // check as far as the right side of the board { if (board.Squares[i].PieceOn) // piece on tile 'i' { furthest_right = (sbyte)(pLocation - (pLocation - i - 1)); // number of spots piece can move right of the location tile break; } } for (sbyte i = (sbyte)(pLocation + 1); i <= (sbyte)(pLocation + range_to_check_left); i++) // check as far as the left side of the board { if (board.Squares[i].PieceOn) { furthest_left = (sbyte)(i - pLocation - 1); // number of spots piece can move left of the location tile break; } } if (furthest_left == -1 && furthest_right == -1) // there are no pieces left or right of the location { pFurthest_Right = (byte)(pLocation - range_to_check_right); pFurthest_Left = (byte)(pLocation + range_to_check_left); return false; } else if (furthest_left == -1) // no piece to the left { pFurthest_Left = (byte)(pLocation + range_to_check_left); pFurthest_Right = (byte)furthest_right; return true; } else if (furthest_right == -1) // no piece to the right { pFurthest_Right = (byte)(pLocation - range_to_check_right); pFurthest_Left = (byte)furthest_left; return true; } else { pFurthest_Left = (byte)furthest_left; pFurthest_Right = (byte)furthest_right; return true; } } }
public abstract bool moveRules(byte pDestination, Board board);
public bool isPieceOnNegativeDiagonal(byte pLocation, out byte pFurthest_Left, out byte pFurthest_Right, Board board) { sbyte furthest_left = -1; // furthest value left of location that a piece can move to sbyte furthest_right = -1; // furthest value right of location that a piece can move to if (pLocation % 8 == 0) { } else if (pLocation % 8 == 7) { } else { } }
public bool isPieceOnPositiveDiagonal(byte pLocation, out byte pFurthest_Left, out byte pFurthest_Right, Board board) { sbyte furthest_left = -1; // furthest value left of location that a piece can move to sbyte furthest_right = -1; // furthest value right of location that a piece can move to sbyte range_to_check_left; // how far we want to check left sbyte range_to_check_right; // how far we want to check right sbyte mod_value = (sbyte)(pLocation % 8); if (pLocation % 8 == 0 || pLocation < 8) { for (sbyte i = (sbyte)(pLocation + 7); (i % 8) <= 7; i += 7) { if (board.Squares[i].PieceOn) { range_to_check_left = (sbyte)(i - 7); break; } } } else if (pLocation % 8 == 7 || pLocation > 55) // if we are on the left-most file { for (sbyte i = (sbyte)(pLocation - 7); (i % 8) <= 0; i -= 7) { if (board.Squares[i].PieceOn) { range_to_check_right = (sbyte)(i + 7); break; } } } else // we are in the middle of the board somewhere { for (sbyte i = (sbyte)(pLocation + 7); (i % 8) <= 7; i += 7) { if (board.Squares[i].PieceOn) { range_to_check_left = (sbyte)(i - 7); break; } } for (sbyte i = (sbyte)(pLocation - 7); (i % 8) <= 0; i -= 7) { if (board.Squares[i].PieceOn) { range_to_check_right = (sbyte)(i + 7); break; } } } }
public bool isPieceOnFile(byte pLocation, out byte pFurthest_Up, out byte pFurthest_Down, Board board) { // look up and down on the file to see if a piece will cause another piece to not be able to move as far sbyte mod_value = (sbyte)(pLocation % 8); sbyte furthest_up = -1; sbyte furthest_down = -1; sbyte top_of_file = -1; sbyte bottom_of_file = mod_value; for (sbyte i = (sbyte)pLocation; i < 64; i += 8) // assign value so we know the top of the file top_of_file = i; if (pLocation == bottom_of_file) { furthest_down = (sbyte)pLocation; for (sbyte i = (sbyte)(pLocation + 8); i <= top_of_file; i += 8) //increase i by 8 to traverse only squares on the same file as location { if (board.Squares[i].PieceOn) { furthest_up = (sbyte)(i - 8); break; } } if (furthest_up == -1) // set out params if no piece is found { pFurthest_Up = (byte)top_of_file; pFurthest_Down = pLocation; return false; } else // set out params if piece is found { pFurthest_Up = (byte)furthest_up; pFurthest_Down = pLocation; return true; } } else if (pLocation == top_of_file) { furthest_up = (sbyte)pLocation; for (sbyte i = (sbyte)(pLocation - 8); i >= bottom_of_file; i -= 8) //decrease i by 8 to traverse only squares on the same file as location { if (board.Squares[i].PieceOn) { furthest_down = (sbyte)(i + 8); break; } } if (furthest_down == -1) // set out params if no piece is found { pFurthest_Down = (byte)bottom_of_file; pFurthest_Up = pLocation; return false; } else // set out params if piece is found { pFurthest_Down = (byte)furthest_down; pFurthest_Up = pLocation; return true; } } else { for (sbyte i = (sbyte)(pLocation - 8); i >= bottom_of_file; i -= 8) // check below location for piece { if (board.Squares[i].PieceOn) { furthest_down = (sbyte)(i + 8); break; } } for (sbyte i = (sbyte)(pLocation + 8); i <= top_of_file; i += 8) // check above location for piece { if (board.Squares[i].PieceOn) { furthest_up = (sbyte)(i - 8); break; } } if (furthest_down == -1 && furthest_up == -1) // no other piece on file { pFurthest_Down = (byte)bottom_of_file; pFurthest_Up = (byte)top_of_file; return false; } else if (furthest_down == -1) // only a piece above { pFurthest_Down = (byte)bottom_of_file; pFurthest_Up = (byte)furthest_up; return true; } else if (furthest_up == -1) // only a piece below { pFurthest_Down = (byte)furthest_down; pFurthest_Up = (byte)top_of_file; return true; } else // piece above and below { pFurthest_Down = (byte)furthest_down; pFurthest_Up = (byte)furthest_up; return true; } } }
public abstract bool captureRules(byte pDestination, Board board);
public override bool moveRules(byte pDestination, Board board) { byte destination = (byte)pDestination; byte currentPosition = (byte)this.Location; if (this.Color == Colors.WHITE) // white pawn movements { if (!HasMoved) { if (destination == currentPosition + 16 || destination == currentPosition + 8) // first move can go 1 or 2 spots forward return true; else return false; } else { if (destination == currentPosition + 8) // not first move, can go 1 spot return true; else return false; } } else // black pawn movements { if (!HasMoved) { if (destination == currentPosition - 16 || destination == currentPosition - 8) // first move can go 1 or 2 spots forward return true; else return false; } else { if (destination == currentPosition - 8) // not first move, can go 1 spot return true; else return false; } } }
public void initialize_Pieces(ref Board pBoard) { for (byte i = 0; i < 16; i++) { pBoard.PlacePiece(player_Pieces[i].InitialPosition); player_Pieces[i].Location = player_Pieces[i].InitialPosition; // piece's current location is their initial location } }
private void button2_Click(object sender, EventArgs e) { Board board = new Board(); }