I accidentally posted old code. My bad

Here's the latest stuff and the game attached.
/// <summary>
/// This class will be composed by 9x9 board squares and all the shogi pieces
/// It will handle all the data and methods needed for a proper shogi game to take place.
/// </summary>
class ShogiGame
{
#region Variables
/// <summary>
/// Shogi game board
/// </summary>
private ShogiBoardSquare[,] boardSquares = new ShogiBoardSquare[9, 9];
/// <summary>
/// This object will provide methods to check shogi rules.
/// </summary>
protected ShogiRules shogiRules;
/// <summary>
/// Holds wich player is up for the next move.
/// </summary>
private String playerTurn = "Player 1";
/// <summary>
/// This shogipiece list has pieces player 1 has killed and can now use
/// </summary>
private List<ShogiPiece> shogiPiecesInPlayer1Hand = new List<ShogiPiece>();
/// <summary>
/// This shogipiece list has pieces player 2 has killed and can now use
/// </summary>
private List<ShogiPiece> shogiPiecesInPlayer2Hand = new List<ShogiPiece>();
/// <summary>
/// If a king is in check this will be set to true
/// </summary>
private Boolean gameCheck = new Boolean();
#region Create all shogi pieces
// Pieces are named accordingly: pl (player 1 or 2) + piece name + number (if more than one)
// player 1
private ShogiPiece pl1King;
private ShogiPiece pl1Rook;
private ShogiPiece pl1Bishop;
private ShogiPiece pl1Gold1;
private ShogiPiece pl1Gold2;
private ShogiPiece pl1Silver1;
private ShogiPiece pl1Silver2;
private ShogiPiece pl1Knight1;
private ShogiPiece pl1Knight2;
private ShogiPiece pl1Lance1;
private ShogiPiece pl1Lance2;
//player 2
private ShogiPiece pl2King;
private ShogiPiece pl2Rook;
private ShogiPiece pl2Bishop;
private ShogiPiece pl2Gold1;
private ShogiPiece pl2Gold2;
private ShogiPiece pl2Silver1;
private ShogiPiece pl2Silver2;
private ShogiPiece pl2Knight1;
private ShogiPiece pl2Knight2;
private ShogiPiece pl2Lance1;
private ShogiPiece pl2Lance2;
#endregion
#endregion
#region Properties
/// <summary>
/// Gets whose players turn it is for the next move
/// </summary>
/// <returns>Returns either "Player 1" or "Player 2" depending on wich players turn it is for the next move.</returns>
public String PlayerTurn
{
get { return playerTurn; }
set { playerTurn = value; }
}
/// <summary>
/// Shogi Rules property, used to check shogi rules on this shogigame.
/// </summary>
public ShogiRules ShogiRules
{
get { return shogiRules; }
}
/// <summary>
/// Gets the requested square from the array
/// </summary>
/// <param name="x">x coordinates of the shogi board</param>
/// <param name="i">y coordinates of the shogi board</param>
/// <returns>ShogiBoardSquare from the boardSquares array</returns>
public ShogiBoardSquare[,] BoardSquares
{
get { return boardSquares; }
}
/// <summary>
/// Gets pieces in player 2 hand
/// </summary>
public List<ShogiPiece> PieceInHandPlayer2
{
get { return shogiPiecesInPlayer2Hand; }
}
/// <summary>
/// Gets pieces in player 1 hand
/// </summary>
public List<ShogiPiece> PieceInHandPlayer1
{
get { return shogiPiecesInPlayer1Hand; }
}
public Boolean GameCheck { get { return gameCheck; } }
#endregion
/// <summary>
/// Default Constructor
/// </summary>
public ShogiGame()
{
this.Initialize();
// Initialize the shogirules object with a reference to the memory address of boardSquares
shogiRules = new ShogiRules(ref boardSquares);
}
/// <summary>
/// Creates the squares, pieces and other data required
/// for a proper shogi game. Sets all data required to
/// initialize a game.
/// (Restarts game)
/// </summary>
public void Initialize()
{
// Create board squares
for (int i = 0; i < 9; i++)
{
for (int x = 0; x < 9; x++)
{
// Default constructor will be run on all boardSquares
// Else the object would be assigned to null
boardSquares[i, x] = new ShogiBoardSquare();
}
}
// Create shogi pieces
#region Create player 1 pieces
// player 1 pieces
pl1King = new ShogiPiece("King", "Player 1", "p1Ki0");
pl1Rook = new ShogiPiece("Rook", "Player 1", "p1Ro0");
pl1Bishop = new ShogiPiece("Bishop", "Player 1", "p1Bi0");
pl1Gold1 = new ShogiPiece("Gold", "Player 1", "p1Go1");
pl1Gold2 = new ShogiPiece("Gold", "Player 1", "p1Go2");
pl1Silver1 = new ShogiPiece("Silver", "Player 1", "p1Si1");
pl1Silver2 = new ShogiPiece("Silver", "Player 1", "p1Si2");
pl1Knight1 = new ShogiPiece("Knight", "Player 1", "p1Kn1");
pl1Knight2 = new ShogiPiece("Knight", "Player 1", "p1Kn2");
pl1Lance1 = new ShogiPiece("Lance", "Player 1", "p1La1");
pl1Lance2 = new ShogiPiece("Lance", "Player 1", "p1La2");
// Position the shogi pieces
boardSquares[4, 8].PlacePiece(pl1King);
boardSquares[7, 7].PlacePiece(pl1Rook);
boardSquares[1, 7].PlacePiece(pl1Bishop);
boardSquares[3, 8].PlacePiece(pl1Gold1);
boardSquares[5, 8].PlacePiece(pl1Gold2);
boardSquares[6, 8].PlacePiece(pl1Silver1);
boardSquares[2, 8].PlacePiece(pl1Silver2);
boardSquares[1, 8].PlacePiece(pl1Knight1);
boardSquares[7, 8].PlacePiece(pl1Knight2);
boardSquares[0, 8].PlacePiece(pl1Lance1);
boardSquares[8, 8].PlacePiece(pl1Lance2);
// Creates 9 pawn pieces each with the name p1Pa[n] - n = pawn number
ShogiPiece[] pl1Pawn = new ShogiPiece[9];
for (int i = 0; i < 9; i++)
{
// Initialize shogipieces
pl1Pawn[i] = new ShogiPiece("Pawn", "Player 1", "p1Pa" + i.ToString());
// Position the pawns
boardSquares[i, 6].PlacePiece(pl1Pawn[i]);
}
#endregion
#region create player 2 pieces
// player 1 pieces
pl2King = new ShogiPiece("King", "Player 2", "p2Ki0");
pl2Rook = new ShogiPiece("Rook", "Player 2", "p2Ro0");
pl2Bishop = new ShogiPiece("Bishop", "Player 2", "p2Bi0");
pl2Gold1 = new ShogiPiece("Gold", "Player 2", "p2Go1");
pl2Gold2 = new ShogiPiece("Gold", "Player 2", "p2Go2");
pl2Silver1 = new ShogiPiece("Silver", "Player 2", "p2Si1");
pl2Silver2 = new ShogiPiece("Silver", "Player 2", "p2Si2");
pl2Knight1 = new ShogiPiece("Knight", "Player 2", "p2Kn1");
pl2Knight2 = new ShogiPiece("Knight", "Player 2", "p2Kn2");
pl2Lance1 = new ShogiPiece("Lance", "Player 2", "p2La1");
pl2Lance2 = new ShogiPiece("Lance", "Player 2", "p2La2");
// Position the shogi pieces
boardSquares[4, 0].PlacePiece(pl2King);
boardSquares[1, 1].PlacePiece(pl2Rook);
boardSquares[7, 1].PlacePiece(pl2Bishop);
boardSquares[3, 0].PlacePiece(pl2Gold1);
boardSquares[5, 0].PlacePiece(pl2Gold2);
boardSquares[6, 0].PlacePiece(pl2Silver1);
boardSquares[2, 0].PlacePiece(pl2Silver2);
boardSquares[1, 0].PlacePiece(pl2Knight1);
boardSquares[7, 0].PlacePiece(pl2Knight2);
boardSquares[0, 0].PlacePiece(pl2Lance1);
boardSquares[8, 0].PlacePiece(pl2Lance2);
// Creates 9 pawn pieces each with the name p1Pa[n] - n = pawn number
ShogiPiece[] pl2Pawn = new ShogiPiece[9];
for (int i = 0; i < 9; i++)
{
// Initialize new shogipieces
pl2Pawn[i] = new ShogiPiece("Pawn", "Player 2", "p2Pa" + i.ToString());
// Position the pawns
boardSquares[i, 2].PlacePiece(pl2Pawn[i]);
}
#endregion
}
/// <summary>
/// Moves the chesspiece from old coordinates to the new coordinates provided that the move is legal according to shogi rules
/// </summary>
/// <param name="oldX">old x coordinates</param>
/// <param name="oldY">old y coordinates</param>
/// <param name="newX">new x coordinates the piece will be placed on</param>
/// <param name="newY">new y coordinates the piece will be placed on</param>
public void MovePiece(int oldX, int oldY, int newX, int newY)
{
ShogiBoardSquare[,] tempSquares = boardSquares;
String tempPlayer = playerTurn;
// Check wether the move is legal for the shogipiece on the old coordinates.
if (shogiRules.IsLegalMove(oldX, oldY, newX, newY))
{
if (BoardSquares[oldX, oldY].GetPieceOnSquare().GetOwner() == playerTurn)
{
// If player 2 kills a piece it goes into his hand
if (boardSquares[newX, newY].GetPieceOnSquare().PieceID != " --- ")
{
if (boardSquares[newX, newY].GetPieceOnSquare().GetOwner() == "Player 2")
{
shogiPiecesInPlayer1Hand.Add(boardSquares[newX, newY].GetPieceOnSquare());
}
if (boardSquares[newX, newY].GetPieceOnSquare().GetOwner() == "Player 1")
{
shogiPiecesInPlayer2Hand.Add(boardSquares[newX, newY].GetPieceOnSquare());
}
}
// Places the piece that was on the old square onto the new square coordinates.
// calls the ShogiSquare method PlacePiece from the new boardSquare coordinates provided (boardSquares[newX,newY]).
//
// PlacePiece(boardSquares[oldX,oldY].GetPieceOnSquare() will place the
// piece that was on the old square onto the new square provided.
boardSquares[newX, newY].PlacePiece(boardSquares[oldX, oldY].GetPieceOnSquare());
// Empty the old square, the shogi piece has successfully been moved to another coordinate by now.
boardSquares[oldX, oldY].EmptySquare();
// Switch player turn
if (playerTurn == "Player 1")
{
playerTurn = "Player 2";
}
else
playerTurn = "Player 1";
if (gameCheck == true)
{
IsKingCheck();
if (gameCheck == true)
{
playerTurn = tempPlayer;
boardSquares = tempSquares;
}
}
if (gameCheck == false)
{
IsKingCheck();
}
}
}
}
/// <summary>
/// Moves a piece from the current players hand to the board
/// </summary>
/// <param name="handListIndex">Index of the list piece in hand</param>
/// <param name="newX">Destination x coordinate</param>
/// <param name="newY">Destination y coordinate</param>
public void MovePieceFromHand(int handListIndex, int newX, int newY)
{
// CHecks wether the square on wich you're placing the piece is empty
if (boardSquares[newX, newY].GetPieceOnSquare().PieceID == " --- ")
{
try
{
if (playerTurn == "Player 1")
{
// Sets the owner of the piece moved to the square to player 1, since player 1 is moving the piece to the board
shogiPiecesInPlayer1Hand[handListIndex].SetOwner("Player 1");
//Places the piece on the square from the players hand
boardSquares[newX, newY].PlacePiece(shogiPiecesInPlayer1Hand[handListIndex]);
// Remove the piece from the pieceInHand list, since it's on the board by now
shogiPiecesInPlayer1Hand.RemoveAt(handListIndex);
}
if (playerTurn == "Player 2")
{
shogiPiecesInPlayer1Hand[handListIndex].SetOwner("Player 2");
boardSquares[newX, newY].PlacePiece(shogiPiecesInPlayer2Hand[handListIndex]);
shogiPiecesInPlayer2Hand.RemoveAt(handListIndex);
}
// Switch player turn
if (playerTurn == "Player 1")
{
playerTurn = "Player 2";
}
else
playerTurn = "Player 1";
}
catch (ArgumentOutOfRangeException) { }
}
}
/// <summary>
/// this function sets the state of the game if either king is in check
/// </summary>
private void IsKingCheck()
{
for (int i = 0; i < 8; i++)
{
for (int x = 0; x < 9; x++)
{
if (shogiRules.IsKingInCheck(x, i))
{
gameCheck = true;
return;
}
}
}
gameCheck = false;
}
}
/// <summary>
///
/// </summary>
class ShogiRules
{
private ShogiBoardSquare[,] boardSquares = new ShogiBoardSquare[9, 9];
/// <summary>
/// Default constructor
/// </summary>
/// <param name="inGame">reference to address of an array (9,9) of squares</param>
public ShogiRules(ref ShogiBoardSquare[,] inGame)
{
boardSquares = inGame;
}
/// <summary>
/// Checks if a move from the old coordinates to the new coordinates is legal depending on what shogi piece is on the given oldX and oldY square.
/// </summary>
/// <param name="oldX">int, old X coordinates</param>
/// <param name="oldY">int, old Y coordinates</param>
/// <param name="newX">int, destination X coordinates</param>
/// <param name="newY">int, destination Y coordinates</param>
/// <returns></returns>
public Boolean IsLegalMove(int oldX, int oldY, int newX, int newY)
{
// piece is on the oldX and oldY coordinates
ShogiPiece pieceOnSquare = boardSquares[oldX, oldY].GetPieceOnSquare();
// If the newX and newY coordinates already have a piece in the same team as the piece being moved then that move is illegal
if (boardSquares[newX, newY].GetPieceOnSquare().GetOwner() == pieceOnSquare.GetOwner())
{
return false;
}
// If the player puts the piece on the same square then it won't be considered a move.
if (newX == oldX && newY == oldY)
{
return false;
}
#region Check for legal pawn move
if (pieceOnSquare.PieceName == "Pawn")
{
// If pawn is owned by player 1 then oldY - newY will be 1 because player 1 moves up (if it's a legal move).
if (pieceOnSquare.GetOwner() == "Player 1")
{
if (oldY - newY == 1 && oldX - newX == 0)
{
CheckPromotedPlayer1(newX, newY);
return true;
}
}
// If pawn is owned by player 2 then newY - oldY will be 1 because player 2 moves down (if it's a legal move).
if (pieceOnSquare.GetOwner() == "Player 2")
{
if (newY - oldY == 1 && oldX - newX == 0)
{
CheckPromotedPlayer2(newX, newY);
return true;
}
}
}
#endregion
#region check for legal knight move
if (pieceOnSquare.PieceName == "Knight")
{
// Movement for knight will be 2 steps up for player 1 so if (oldY - newY == 2) and a step right or left |oldX-newX| == 1
if (pieceOnSquare.GetOwner() == "Player 1")
{
if (oldY - newY == 2 && Math.Abs(oldX - newX) == 1)
{
CheckPromotedPlayer1(newX, newY);
return true;
}
}
if (pieceOnSquare.GetOwner() == "Player 2")
{
if (newY - oldY == 2 && Math.Abs(oldX - newX) == 1)
{
CheckPromotedPlayer2(newX, newY);
return true;
}
}
}
#endregion
#region Check for legal silver move
if (pieceOnSquare.PieceName == "Silver")
{
//
if (pieceOnSquare.GetOwner() == "Player 1")
{
// Silver for player 1 moves up and has the 3 spaces on the x axis available, or it moves down and can go right or left
if ((oldY - newY == 1 && oldX - newX == 0 || oldY - newY == 1 && Math.Abs(oldX - newX) == 1) || (oldY - newY == -1 && (oldX - newX == 1 || newX - oldX == 1)))
{
CheckPromotedPlayer1(newX, newY);
return true;
}
}
//
if (pieceOnSquare.GetOwner() == "Player 2")
{
// Opposite from player's 1 perspective so oldY and newY (and X) are swapped.
if ((newY - oldY == 1 && newX - oldX == 0 || newY - oldY == 1 && Math.Abs(newX - oldX) == 1) || (newY - oldY == -1 && (newX - oldX == 1 || oldX - newX == 1)))
{
CheckPromotedPlayer2(newX, newY);
return true;
}
}
}
#endregion
#region Check for legal Gold move
if (pieceOnSquare.PieceName == "Gold")
{
// a gold for player 1 can move up and either left or right or straight, or it can move to it's sides, or it can go a unit back.
if (pieceOnSquare.GetOwner() == "Player 1")
{
if ((oldY - newY == 1 && oldX - newX == 0 || oldY - newY == 1 && Math.Abs(oldX - newX) == 1) || (Math.Abs(newX - oldX) == 1 && oldY - newY == 0) || (newX - oldX == 0 && newY - oldY == 1))
{
return true;
}
}
//
if (pieceOnSquare.GetOwner() == "Player 2")
{
// Opposite from player's 1 perspective so oldY and newY (and X) are swapped.
if ((newY - oldY == 1 && newX - oldX == 0 || newY - oldY == 1 && Math.Abs(newX - oldX) == 1) || (Math.Abs(oldX - newX) == 1 && newY - oldY == 0) || (oldX - newX == 0 && oldY - newY == 1))
{
return true;
}
}
}
#endregion
#region Check for legal King move
if (pieceOnSquare.PieceName == "King")
{
// King can move one unit in all directions.
if ((oldY - newY == 1 && oldX - newX == 0 || oldY - newY == 1 && Math.Abs(oldX - newX) == 1) || (Math.Abs(newX - oldX) == 1 && oldY - newY == 0) || (newX - oldX == 0 && newY - oldY == 1) || (Math.Abs(newX - oldX) == 1 && newY - oldY == 1))
{
if (pieceOnSquare.GetOwner() == "Player 1")
{
CheckPromotedPlayer1(newX, newY);
}
if (pieceOnSquare.GetOwner() == "Player 2")
{
CheckPromotedPlayer2(newX, newY);
}
return true;
}
}
#endregion
#region Check for legal Lance move
if (pieceOnSquare.PieceName == "Lance")
{
// a lance can move as many open square forwards as possible but not backwards
if (pieceOnSquare.GetOwner() == "Player 1")
{
// Lance can not move to either side, only forwards.
if (newX - oldX == 0 && oldY - newY >= 0)
{
// CHeck if there's a piece in the way
for (int i = 1; i < oldY - newY; i++)
{
// Counts from oldY by i in the boardsquares array to see if there's a piece in the lance's way.
// returns a false if there's a piece in the way
if (boardSquares[oldX, oldY - i].GetPieceOnSquare().PieceID != " --- ")
{
return false;
}
}
CheckPromotedPlayer1(newX, newY);
return true;
}
}
//
if (pieceOnSquare.GetOwner() == "Player 2")
{
if (newX - oldX == 0 && oldY - newY <= 0)
{
// CHeck if there's a piece in the way
for (int i = 1; i < newY - oldY; i++)
{
if (boardSquares[oldX, oldY + i].GetPieceOnSquare().PieceID != " --- ")
{
return false;
}
}
CheckPromotedPlayer2(newX, newY);
return true;
}
}
}
#endregion
#region Check for legal Rook move
if (pieceOnSquare.PieceName == "Rook")
{
#region Check up and down moves (First check is commented)
// Comments apply to all directions.
// oldY - newY is bigger than 0 then the piece has been moved up
if (newX - oldX == 0 && oldY - newY >= 0)
{
// Go from i = 1 because i = 0 is the location of the pice being moved
for (int i = 1; i < oldY - newY; i++)
{
// the loop will count down from oldY by i and check each time in the boardSquares array if there's a piece in the square being checked.
// If there's a piece in the square in the way between oldY and newY then this method will return a false. This will prevent
// The possibility of pieces overlapping.
if (boardSquares[oldX, oldY - i].GetPieceOnSquare().PieceID != " --- ")
{
return false;
}
}
// If the method doesn't find a shogi piece in the way from oldX and newX
// then it will return that the piece can make a legal move to that location. Since there's nothing
// in it's way preventing it from moving.
if (pieceOnSquare.GetOwner() == "Player 1")
{
CheckPromotedPlayer1(newX, newY);
}
if (pieceOnSquare.GetOwner() == "Player 2")
{
CheckPromotedPlayer2(newX, newY);
}
return true;
}
// Go down
if (newX - oldX == 0 && oldY - newY <= 0)
{
// CHeck if there's a piece in it's way down
for (int i = 1; i < newY - oldY; i++)
{
if (boardSquares[oldX, oldY + i].GetPieceOnSquare().PieceID != " --- ")
{
return false;
}
}
if (pieceOnSquare.GetOwner() == "Player 1")
{
CheckPromotedPlayer1(newX, newY);
}
if (pieceOnSquare.GetOwner() == "Player 2")
{
CheckPromotedPlayer2(newX, newY);
}
return true;
}
#endregion
#region check left and right moves
if (newY - oldY == 0 && oldX - newX >= 0)
{
// CHeck if there's a piece in the way left
for (int i = 1; i < oldX - newX; i++)
{
if (boardSquares[oldX - i, oldY].GetPieceOnSquare().PieceID != " --- ")
{
return false;
}
}
if (pieceOnSquare.GetOwner() == "Player 1")
{
CheckPromotedPlayer1(newX, newY);
}
if (pieceOnSquare.GetOwner() == "Player 2")
{
CheckPromotedPlayer2(newX, newY);
}
return true;
}
if (newY - oldY == 0 && oldX - newX <= 0)
{
// CHeck if there's a piece in the way right
for (int i = 1; i < newX - oldX; i++)
{
if (boardSquares[oldX + i, oldY].GetPieceOnSquare().PieceID != " --- ")
{
return false;
}
}
if (pieceOnSquare.GetOwner() == "Player 1")
{
CheckPromotedPlayer1(newX, newY);
}
if (pieceOnSquare.GetOwner() == "Player 2")
{
CheckPromotedPlayer2(newX, newY);
}
return true;
}
#endregion
}
#endregion
#region Check for legal Bishop move
if (pieceOnSquare.PieceName == "Bishop")
{
if ((Math.Abs(oldY - newY) == Math.Abs(oldX - newX) && Math.Abs(oldX - newX) == Math.Abs(oldY - newY)))
{
#region up - left or right
// Up right
if (oldY - newY >= 0 && newX - oldX >= 0)
{
for (int i = 1; i < newX - oldX; i++)
{
if (boardSquares[oldX + i, oldY - i].GetPieceOnSquare().PieceID != " --- ")
{
return false;
}
}
if (pieceOnSquare.GetOwner() == "Player 1")
{
CheckPromotedPlayer1(newX, newY);
}
if (pieceOnSquare.GetOwner() == "Player 2")
{
CheckPromotedPlayer2(newX, newY);
}
return true;
}
// Up left
if (oldY - newY >= 0 && oldX - newX >= 0)
{
for (int i = 1; i < oldX - newX; i++)
{
if (boardSquares[oldX - i, oldY - i].GetPieceOnSquare().PieceID != " --- ")
{
return false;
}
}
if (pieceOnSquare.GetOwner() == "Player 1")
{
CheckPromotedPlayer1(newX, newY);
}
if (pieceOnSquare.GetOwner() == "Player 2")
{
CheckPromotedPlayer2(newX, newY);
}
return true;
}
#endregion
#region down - left or right
// Up right
if (newY - oldY >= 0 && newX - oldX >= 0)
{
for (int i = 1; i < newX - oldX; i++)
{
if (boardSquares[oldX + i, oldY + i].GetPieceOnSquare().PieceID != " --- ")
{
return false;
}
}
if (pieceOnSquare.GetOwner() == "Player 1")
{
CheckPromotedPlayer1(newX, newY);
}
if (pieceOnSquare.GetOwner() == "Player 2")
{
CheckPromotedPlayer2(newX, newY);
}
return true;
}
// Up left
if (newY - oldY >= 0 && oldX - newX >= 0)
{
for (int i = 1; i < oldX - newX; i++)
{
if (boardSquares[oldX - i, oldY + i].GetPieceOnSquare().PieceID != " --- ")
{
return false;
}
}
if (pieceOnSquare.GetOwner() == "Player 1")
{
CheckPromotedPlayer1(newX, newY);
}
if (pieceOnSquare.GetOwner() == "Player 2")
{
CheckPromotedPlayer2(newX, newY);
}
return true;
}
#endregion
}
}
#endregion
#region Check for legal promoted pieces move
if (boardSquares[oldX, oldY].GetPromoted() == true)
{
#region pawn silver lance knight
if (pieceOnSquare.PieceName == "Pawn" || pieceOnSquare.PieceName == "Silver" || pieceOnSquare.PieceName == "Lance" || pieceOnSquare.PieceName == "Knight")
{
// a gold for player 1 can move up and either left or right or straight, or it can move to it's sides, or it can go a unit back.
if (pieceOnSquare.GetOwner() == "Player 1")
{
if ((oldY - newY == 1 && oldX - newX == 0 || oldY - newY == 1 && Math.Abs(oldX - newX) == 1) || (Math.Abs(newX - oldX) == 1 && oldY - newY == 0) || (newX - oldX == 0 && newY - oldY == 1))
{
return true;
}
}
//
if (pieceOnSquare.GetOwner() == "Player 2")
{
// Opposite from player's 1 perspective so oldY and newY (and X) are swapped.
if ((newY - oldY == 1 && newX - oldX == 0 || newY - oldY == 1 && Math.Abs(newX - oldX) == 1) || (Math.Abs(oldX - newX) == 1 && newY - oldY == 0) || (oldX - newX == 0 && oldY - newY == 1))
{
return true;
}
}
}
#endregion
#region bishop
if (pieceOnSquare.PieceName == "Bishop")
{
#region squares around piece
if ((oldY - newY == 1 && oldX - newX == 0 || oldY - newY == 1 && Math.Abs(oldX - newX) == 1) || (Math.Abs(newX - oldX) == 1 && oldY - newY == 0) || (newX - oldX == 0 && newY - oldY == 1) || (Math.Abs(newX - oldX) == 1 && newY - oldY == 1))
{
return true;
}
#endregion
if ((Math.Abs(oldY - newY) == Math.Abs(oldX - newX) && Math.Abs(oldX - newX) == Math.Abs(oldY - newY)))
{
#region up - left or right
// Up right
if (oldY - newY >= 0 && newX - oldX >= 0)
{
for (int i = 1; i < newX - oldX; i++)
{
if (boardSquares[oldX + i, oldY - i].GetPieceOnSquare().PieceID != " --- ")
{
return false;
}
}
return true;
}
// Up left
if (oldY - newY >= 0 && oldX - newX >= 0)
{
for (int i = 1; i < oldX - newX; i++)
{
if (boardSquares[oldX - i, oldY - i].GetPieceOnSquare().PieceID != " --- ")
{
return false;
}
}
return true;
}
#endregion
#region down - left or right
// Up right
if (newY - oldY >= 0 && newX - oldX >= 0)
{
for (int i = 1; i < newX - oldX; i++)
{
if (boardSquares[oldX + i, oldY + i].GetPieceOnSquare().PieceID != " --- ")
{
return false;
}
}
return true;
}
// Up left
if (newY - oldY >= 0 && oldX - newX >= 0)
{
for (int i = 1; i < oldX - newX; i++)
{
if (boardSquares[oldX - i, oldY + i].GetPieceOnSquare().PieceID != " --- ")
{
return false;
}
}
return true;
}
#endregion
}
}
#endregion
#region Rook
if (pieceOnSquare.PieceName == "Rook")
{
#region squares around piece
if ((oldY - newY == 1 && oldX - newX == 0 || oldY - newY == 1 && Math.Abs(oldX - newX) == 1) || (Math.Abs(newX - oldX) == 1 && oldY - newY == 0) || (newX - oldX == 0 && newY - oldY == 1) || (Math.Abs(newX - oldX) == 1 && newY - oldY == 1))
{
return true;
}
#endregion
#region Check up and down moves (First check is commented)
// Comments apply to all directions.
// oldY - newY is bigger than 0 then the piece has been moved up
if (newX - oldX == 0 && oldY - newY >= 0)
{
// Go from i = 1 because i = 0 is the location of the pice being moved
for (int i = 1; i < oldY - newY; i++)
{
// the loop will count down from oldY by i and check each time in the boardSquares array if there's a piece in the square being checked.
// If there's a piece in the square in the way between oldY and newY then this method will return a false. This will prevent
// The possibility of pieces overlapping.
if (boardSquares[oldX, oldY - i].GetPieceOnSquare().PieceID != " --- ")
{
return false;
}
}
// If the method doesn't find a shogi piece in the way from oldX and newX
// then it will return that the piece can make a legal move to that location. Since there's nothing
// in it's way preventing it from moving.
if (pieceOnSquare.GetOwner() == "Player 1")
{
CheckPromotedPlayer1(newX, newY);
}
if (pieceOnSquare.GetOwner() == "Player 2")
{
CheckPromotedPlayer2(newX, newY);
}
return true;
}
// Go down
if (newX - oldX == 0 && oldY - newY <= 0)
{
// CHeck if there's a piece in it's way down
for (int i = 1; i < newY - oldY; i++)
{
if (boardSquares[oldX, oldY + i].GetPieceOnSquare().PieceID != " --- ")
{
return false;
}
}
if (pieceOnSquare.GetOwner() == "Player 1")
{
CheckPromotedPlayer1(newX, newY);
}
if (pieceOnSquare.GetOwner() == "Player 2")
{
CheckPromotedPlayer2(newX, newY);
}
return true;
}
#endregion
#region check left and right moves
if (newY - oldY == 0 && oldX - newX >= 0)
{
// CHeck if there's a piece in the way left
for (int i = 1; i < oldX - newX; i++)
{
if (boardSquares[oldX - i, oldY].GetPieceOnSquare().PieceID != " --- ")
{
return false;
}
}
if (pieceOnSquare.GetOwner() == "Player 1")
{
CheckPromotedPlayer1(newX, newY);
}
if (pieceOnSquare.GetOwner() == "Player 2")
{
CheckPromotedPlayer2(newX, newY);
}
return true;
}
if (newY - oldY == 0 && oldX - newX <= 0)
{
// CHeck if there's a piece in the way right
for (int i = 1; i < newX - oldX; i++)
{
if (boardSquares[oldX + i, oldY - i].GetPieceOnSquare().PieceID != " --- ")
{
return false;
}
}
if (pieceOnSquare.GetOwner() == "Player 1")
{
CheckPromotedPlayer1(newX, newY);
}
if (pieceOnSquare.GetOwner() == "Player 2")
{
CheckPromotedPlayer2(newX, newY);
}
return true;
}
#endregion
}
#endregion
}
#endregion
// In case of move not being legal.
return false;
}
public Boolean IsKingInCheck(int X, int Y)
{
#region Pawn
if (boardSquares[X, Y].GetPieceOnSquare().PieceName == "Pawn")
{
// Player 1
try
{
if (boardSquares[X, Y].GetPieceOnSquare().GetOwner() == "Player 1" && boardSquares[X, Y - 1].GetPieceOnSquare().GetOwner() == "Player 2" && boardSquares[X, Y - 1].GetPieceOnSquare().PieceName == "King")
{
return true;
}
if (boardSquares[X, Y].GetPieceOnSquare().GetOwner() == "Player 2" && boardSquares[X, Y + 1].GetPieceOnSquare().GetOwner() == "Player 1" && boardSquares[X, Y + 1].GetPieceOnSquare().PieceName == "King")
{
return true;
}
}
catch (IndexOutOfRangeException)
{ // BoardSquares index was out of range
}
}
#endregion
#region Gold
if (boardSquares[X, Y].GetPieceOnSquare().PieceName == "Gold")
{
// Player 1
try
{
if (boardSquares[X, Y].GetPieceOnSquare().GetOwner() == "Player 1" && boardSquares[X, Y - 1].GetPieceOnSquare().GetOwner() == "Player 2" && boardSquares[X, Y - 1].GetPieceOnSquare().PieceName == "King"
|| boardSquares[X, Y].GetPieceOnSquare().GetOwner() == "Player 1" && boardSquares[X - 1, Y - 1].GetPieceOnSquare().GetOwner() == "Player 2" && boardSquares[X - 1, Y - 1].GetPieceOnSquare().PieceName == "King"
|| boardSquares[X, Y].GetPieceOnSquare().GetOwner() == "Player 1" && boardSquares[X + 1, Y - 1].GetPieceOnSquare().GetOwner() == "Player 2" && boardSquares[X + 1, Y - 1].GetPieceOnSquare().PieceName == "King"
|| boardSquares[X, Y].GetPieceOnSquare().GetOwner() == "Player 1" && boardSquares[X + 1, Y].GetPieceOnSquare().GetOwner() == "Player 2" && boardSquares[X + 1, Y].GetPieceOnSquare().PieceName == "King"
|| boardSquares[X, Y].GetPieceOnSquare().GetOwner() == "Player 1" && boardSquares[X - 1, Y].GetPieceOnSquare().GetOwner() == "Player 2" && boardSquares[X - 1, Y].GetPieceOnSquare().PieceName == "King"
|| boardSquares[X, Y].GetPieceOnSquare().GetOwner() == "Player 1" && boardSquares[X, Y + 1].GetPieceOnSquare().GetOwner() == "Player 2" && boardSquares[X, Y + 1].GetPieceOnSquare().PieceName == "King"
)
{
return true;
}
if (boardSquares[X, Y].GetPieceOnSquare().GetOwner() == "Player 2" && boardSquares[X, Y + 1].GetPieceOnSquare().GetOwner() == "Player 1" && boardSquares[X, Y + 1].GetPieceOnSquare().PieceName == "King"
|| boardSquares[X, Y].GetPieceOnSquare().GetOwner() == "Player 2" && boardSquares[X - 1, Y + 1].GetPieceOnSquare().GetOwner() == "Player 1" && boardSquares[X - 1, Y + 1].GetPieceOnSquare().PieceName == "King"
|| boardSquares[X, Y].GetPieceOnSquare().GetOwner() == "Player 2" && boardSquares[X + 1, Y + 1].GetPieceOnSquare().GetOwner() == "Player 1" && boardSquares[X + 1, Y + 1].GetPieceOnSquare().PieceName == "King"
|| boardSquares[X, Y].GetPieceOnSquare().GetOwner() == "Player 2" && boardSquares[X + 1, Y].GetPieceOnSquare().GetOwner() == "Player 1" && boardSquares[X + 1, Y].GetPieceOnSquare().PieceName == "King"
|| boardSquares[X, Y].GetPieceOnSquare().GetOwner() == "Player 2" && boardSquares[X - 1, Y].GetPieceOnSquare().GetOwner() == "Player 1" && boardSquares[X - 1, Y].GetPieceOnSquare().PieceName == "King"
|| boardSquares[X, Y].GetPieceOnSquare().GetOwner() == "Player 2" && boardSquares[X, Y - 1].GetPieceOnSquare().GetOwner() == "Player 1" && boardSquares[X, Y - 1].GetPieceOnSquare().PieceName == "King"
)
{
return true;
}
}
catch (IndexOutOfRangeException)
{ // BoardSquares index was out of range
}
}
#endregion
#region Silver
if (boardSquares[X, Y].GetPieceOnSquare().PieceName == "Silver")
{
// Player 1
try
{
if (boardSquares[X, Y].GetPieceOnSquare().GetOwner() == "Player 1" && boardSquares[X, Y - 1].GetPieceOnSquare().GetOwner() == "Player 2" && boardSquares[X, Y - 1].GetPieceOnSquare().PieceName == "King"
|| boardSquares[X, Y].GetPieceOnSquare().GetOwner() == "Player 1" && boardSquares[X - 1, Y - 1].GetPieceOnSquare().GetOwner() == "Player 2" && boardSquares[X - 1, Y - 1].GetPieceOnSquare().PieceName == "King"
|| boardSquares[X, Y].GetPieceOnSquare().GetOwner() == "Player 1" && boardSquares[X + 1, Y - 1].GetPieceOnSquare().GetOwner() == "Player 2" && boardSquares[X + 1, Y - 1].GetPieceOnSquare().PieceName == "King"
|| boardSquares[X, Y].GetPieceOnSquare().GetOwner() == "Player 1" && boardSquares[X - 1, Y + 1].GetPieceOnSquare().GetOwner() == "Player 2" && boardSquares[X - 1, Y + 1].GetPieceOnSquare().PieceName == "King"
|| boardSquares[X, Y].GetPieceOnSquare().GetOwner() == "Player 1" && boardSquares[X + 1, Y + 1].GetPieceOnSquare().GetOwner() == "Player 2" && boardSquares[X + 1, Y + 1].GetPieceOnSquare().PieceName == "King"
)
{
return true;
}
if (boardSquares[X, Y].GetPieceOnSquare().GetOwner() == "Player 2" && boardSquares[X, Y + 1].GetPieceOnSquare().GetOwner() == "Player 1" && boardSquares[X, Y + 1].GetPieceOnSquare().PieceName == "King"
|| boardSquares[X, Y].GetPieceOnSquare().GetOwner() == "Player 2" && boardSquares[X - 1, Y + 1].GetPieceOnSquare().GetOwner() == "Player 1" && boardSquares[X - 1, Y + 1].GetPieceOnSquare().PieceName == "King"
|| boardSquares[X, Y].GetPieceOnSquare().GetOwner() == "Player 2" && boardSquares[X + 1, Y + 1].GetPieceOnSquare().GetOwner() == "Player 1" && boardSquares[X + 1, Y + 1].GetPieceOnSquare().PieceName == "King"
|| boardSquares[X, Y].GetPieceOnSquare().GetOwner() == "Player 1" && boardSquares[X - 1, Y - 1].GetPieceOnSquare().GetOwner() == "Player 2" && boardSquares[X - 1, Y - 1].GetPieceOnSquare().PieceName == "King"
|| boardSquares[X, Y].GetPieceOnSquare().GetOwner() == "Player 1" && boardSquares[X + 1, Y - 1].GetPieceOnSquare().GetOwner() == "Player 2" && boardSquares[X + 1, Y - 1].GetPieceOnSquare().PieceName == "King"
)
{
return true;
}
}
catch (IndexOutOfRangeException)
{ // BoardSquares index was out of range
}
}
#endregion
#region Knight
if (boardSquares[X, Y].GetPieceOnSquare().PieceName == "Knight")
{
// Player 1
try
{
if (boardSquares[X, Y].GetPieceOnSquare().GetOwner() == "Player 1" && boardSquares[X - 1, Y - 2].GetPieceOnSquare().GetOwner() == "Player 2" && boardSquares[X - 1, Y - 2].GetPieceOnSquare().PieceName == "King"
|| boardSquares[X, Y].GetPieceOnSquare().GetOwner() == "Player 1" && boardSquares[X + 1, Y - 2].GetPieceOnSquare().GetOwner() == "Player 2" && boardSquares[X + 1, Y - 2].GetPieceOnSquare().PieceName == "King"
)
{
return true;
}
if (boardSquares[X, Y].GetPieceOnSquare().GetOwner() == "Player 2" && boardSquares[X - 1, Y + 2].GetPieceOnSquare().GetOwner() == "Player 1" && boardSquares[X - 1, Y + 2].GetPieceOnSquare().PieceName == "King"
|| boardSquares[X, Y].GetPieceOnSquare().GetOwner() == "Player 2" && boardSquares[X + 1, Y + 2].GetPieceOnSquare().GetOwner() == "Player 1" && boardSquares[X + 1, Y + 2].GetPieceOnSquare().PieceName == "King"
)
{
return true;
}
}
catch (IndexOutOfRangeException)
{ // BoardSquares index was out of range
}
}
#endregion
#region Lance
if (boardSquares[X, Y].GetPieceOnSquare().PieceName == "Lance")
{
// Player 1
try
{
for (int i = 0; i < 9; i++)
{
try
{
if (boardSquares[X, Y].GetPieceOnSquare().GetOwner() == "Player 1" && boardSquares[X, Y - i].GetPieceOnSquare().GetOwner() == "Player 2" && boardSquares[X, Y - i].GetPieceOnSquare().PieceName == "King")
{
return true;
}
if (boardSquares[X, Y].GetPieceOnSquare().GetOwner() == "Player 1" && boardSquares[X, Y - i].GetPieceOnSquare().GetOwner() == "Player 2" && boardSquares[X, Y - i].GetPieceOnSquare().PieceName != "King")
{
break;
}
if (boardSquares[X, Y].GetPieceOnSquare().GetOwner() == "Player 2" && boardSquares[X, Y + i].GetPieceOnSquare().GetOwner() == "Player 1" && boardSquares[X, Y + i].GetPieceOnSquare().PieceName == "King")
{
return true;
}
if (boardSquares[X, Y].GetPieceOnSquare().GetOwner() == "Player 2" && boardSquares[X, Y + i].GetPieceOnSquare().GetOwner() == "Player 1" && boardSquares[X, Y + i].GetPieceOnSquare().PieceName != "King")
{
break;
}
}
catch (Exception) { }
}
}
catch (IndexOutOfRangeException)
{ // BoardSquares index was out of range
}
}
#endregion
#region Rook
if (boardSquares[X, Y].GetPieceOnSquare().PieceName == "Rook")
{
// Player 1
#region up
for (int i = 0; i < 9; i++)
{
try
{
if (boardSquares[X, Y].GetPieceOnSquare().GetOwner() == "Player 1" && boardSquares[X, Y - i].GetPieceOnSquare().GetOwner() == "Player 2" && boardSquares[X, Y - i].GetPieceOnSquare().PieceName == "King")
{
return true;
}
if (boardSquares[X, Y].GetPieceOnSquare().GetOwner() == "Player 1" && boardSquares[X, Y - i].GetPieceOnSquare().GetOwner() == "Player 2" && boardSquares[X, Y - i].GetPieceOnSquare().PieceName != "King")
{
break;
}
if (boardSquares[X, Y].GetPieceOnSquare().GetOwner() == "Player 2" && boardSquares[X, Y + i].GetPieceOnSquare().GetOwner() == "Player 1" && boardSquares[X, Y + i].GetPieceOnSquare().PieceName == "King")
{
return true;
}
if (boardSquares[X, Y].GetPieceOnSquare().GetOwner() == "Player 2" && boardSquares[X, Y + i].GetPieceOnSquare().GetOwner() == "Player 1" && boardSquares[X, Y + i].GetPieceOnSquare().PieceName != "King")
{
break;
}
}
catch (Exception) { }
}
#endregion
#region down
for (int i = 0; i < 9; i++)
{
try
{
if (boardSquares[X, Y].GetPieceOnSquare().GetOwner() == "Player 1" && boardSquares[X, Y + i].GetPieceOnSquare().GetOwner() == "Player 2" && boardSquares[X, Y + i].GetPieceOnSquare().PieceName == "King")
{
return true;
}
if (boardSquares[X, Y].GetPieceOnSquare().GetOwner() == "Player 1" && boardSquares[X, Y + i].GetPieceOnSquare().GetOwner() == "Player 2" && boardSquares[X, Y + i].GetPieceOnSquare().PieceName != "King")
{
break;
}
if (boardSquares[X, Y].GetPieceOnSquare().GetOwner() == "Player 2" && boardSquares[X, Y - i].GetPieceOnSquare().GetOwner() == "Player 1" && boardSquares[X, Y - i].GetPieceOnSquare().PieceName == "King")
{
return true;
}
if (boardSquares[X, Y].GetPieceOnSquare().GetOwner() == "Player 2" && boardSquares[X, Y - i].GetPieceOnSquare().GetOwner() == "Player 1" && boardSquares[X, Y - i].GetPieceOnSquare().PieceName != "King")
{
break;
}
}
catch (Exception) { }
}
#endregion
#region left
for (int i = 0; i < 9; i++)
{
try
{
if (boardSquares[X, Y].GetPieceOnSquare().GetOwner() == "Player 1" && boardSquares[X + 1, Y].GetPieceOnSquare().GetOwner() == "Player 2" && boardSquares[X + 1, Y].GetPieceOnSquare().PieceName == "King")
{
return true;
}
if (boardSquares[X, Y].GetPieceOnSquare().GetOwner() == "Player 1" && boardSquares[X + 1, Y].GetPieceOnSquare().GetOwner() == "Player 2" && boardSquares[X + 1, Y].GetPieceOnSquare().PieceName != "King")
{
break;
}
if (boardSquares[X, Y].GetPieceOnSquare().GetOwner() == "Player 2" && boardSquares[X + 1, Y].GetPieceOnSquare().GetOwner() == "Player 1" && boardSquares[X + 1, Y].GetPieceOnSquare().PieceName == "King")
{
return true;
}
if (boardSquares[X, Y].GetPieceOnSquare().GetOwner() == "Player 2" && boardSquares[X + 1, Y].GetPieceOnSquare().GetOwner() == "Player 1" && boardSquares[X + 1, Y].GetPieceOnSquare().PieceName != "King")
{
break;
}
}
catch (Exception) { }
}
#endregion
#region right
for (int i = 0; i < 9; i++)
{
try
{
if (boardSquares[X, Y].GetPieceOnSquare().GetOwner() == "Player 1" && boardSquares[X - 1, Y].GetPieceOnSquare().GetOwner() == "Player 2" && boardSquares[X - 1, Y].GetPieceOnSquare().PieceName == "King")
{
return true;
}
if (boardSquares[X, Y].GetPieceOnSquare().GetOwner() == "Player 1" && boardSquares[X - 1, Y].GetPieceOnSquare().GetOwner() == "Player 2" && boardSquares[X - 1, Y].GetPieceOnSquare().PieceName != "King")
{
break;
}
if (boardSquares[X, Y].GetPieceOnSquare().GetOwner() == "Player 2" && boardSquares[X - 1, Y].GetPieceOnSquare().GetOwner() == "Player 1" && boardSquares[X - 1, Y].GetPieceOnSquare().PieceName == "King")
{
return true;
}
if (boardSquares[X, Y].GetPieceOnSquare().GetOwner() == "Player 2" && boardSquares[X - 1, Y].GetPieceOnSquare().GetOwner() == "Player 1" && boardSquares[X - 1, Y].GetPieceOnSquare().PieceName != "King")
{
break;
}
}
catch (Exception) { }
}
#endregion
}
#endregion
return false;
}
/// <summary>
/// Checks if a player has entered a region of the board in wich the shogi piece is promoted.
/// </summary>
/// <param name="newX"></param>
/// <param name="newY"></param>
private void CheckPromotedPlayer1(int newX, int newY)
{
ShogiPiece pieceOnSquare = boardSquares[newX, newY].GetPieceOnSquare();
if (newY <= 2)
{
boardSquares[newX, newY].PromotePiece();
}
}
private void CheckPromotedPlayer2(int newX, int newY)
{
ShogiPiece pieceOnSquare = boardSquares[newX, newY].GetPieceOnSquare();
if (newY >= 6)
{
boardSquares[newX, newY].PromotePiece();
}
}
}
/// <summary>
/// This object represents a single square in the shogi board
/// </summary>
class ShogiBoardSquare
{
/// <summary>
/// If there's a piece on the squre it will be passed to pieceOnSquare
/// </summary>
private ShogiPiece pieceOnSquare;
/// <summary>
/// Holds wether the piece on the square has been promoted
/// </summary>
private Boolean IsPiecePromoted = false;
/// <summary>
/// Default constructor
/// </summary>
public ShogiBoardSquare()
{
pieceOnSquare = new ShogiPiece();
}
/// <summary>
/// Places a shogi piece on this square
/// </summary>
/// <param name="setSquarePiece">Shogipiece passed by value</param>
public void PlacePiece(ShogiPiece setSquarePiece)
{
pieceOnSquare = setSquarePiece;
}
/// <summary>
/// Set's the squares state to empty
/// </summary>
public void EmptySquare()
{
pieceOnSquare = new ShogiPiece();
}
/// <summary>
/// Promote the shogi piece on the square.
/// </summary>
public void PromotePiece()
{
IsPiecePromoted = true;
}
/// <summary>
/// Gets what's on the square
/// </summary>
/// <returns>String value, ID of shogi piece on square</returns>
public String GetSquareState()
{
return pieceOnSquare.PieceID;
}
public ShogiPiece GetPieceOnSquare()
{
return pieceOnSquare;
}
/// <summary>
/// Gets wether piece on the square has been promoted
/// </summary>
/// <returns>IsPiecePromoted Boolean</returns>
public Boolean GetPromoted()
{
return IsPiecePromoted;
}
}
/// <summary>
/// This class allows it's user to create a shogi piece and specify it's name, ID and owner.
/// Used by class ShogiGame
/// </summary>
class ShogiPiece
{
/// <summary>
/// Gets or sets the name of the shogi piece
/// </summary>
private String pieceName;
/// <summary>
/// Unique ID of shogi Piece
/// </summary>
private String pieceID;
/// <summary>
/// Name of the player that owns this shogi piece
/// </summary>
private String playerOwner;
/// <summary>
/// Default constructor
/// </summary>
public ShogiPiece()
{
// Set pieceName to no piece value
pieceName = " --- ";
// No ID
pieceID = " --- ";
}
/// <summary>
/// This constructor takes a string value
/// </summary>
/// <param name="setPieceName">Shogi Piece Name</param>
public ShogiPiece(String setPieceName, String setPlayerName, String setPieceID)
{
// Set the pieceName to the string passed to the constructor
pieceName = setPieceName;
// Set the pieceID to the string passed to the constructor
pieceID = setPieceID;
// Set the player owner to the playername value
playerOwner = setPlayerName;
}
public String PieceName
{
get { return pieceName; }
}
public String PieceID
{
get { return pieceID; }
}
public String GetOwner()
{
return playerOwner;
}
public void SetOwner(String owner)
{
if (owner == "Player 1" || owner == "Player 2")
{
playerOwner = owner;
}
}
}