private void upDateIsKing(Soilder i_Soilder) { if (((int)i_Soilder.m_Possition.m_Row == 0) || ((int)i_Soilder.m_Possition.m_Row == m_Size - 1)) //end of board condision { i_Soilder.IsKing = true; } }
public void InitBlackTeam() { for (int i = ((this.m_Size + 2) / 2); i < this.m_Size; i++) { for (int j = 0; j < this.m_Size; j++) { if (i % 2 != 0) { if (j % 2 == 0) { Possition tempPossition = new Possition(j, i); Soilder tempSoilder = new Soilder(Soilder.Group.Black, tempPossition); InsertSoilder(tempSoilder); } } else { if (j % 2 != 0) { Possition tempPossition = new Possition(j, i); Soilder tempSoilder = new Soilder(Soilder.Group.Black, tempPossition); InsertSoilder(tempSoilder); } } } } }
public void InitWhiteTeam() { for (int i = 0; i < (this.m_Size - 2) / 2; i++) { for (int j = 0; j < this.m_Size; j++) { //if the row is even if (i % 2 == 0) { if (j % 2 != 0) { Possition tempPossition = new Possition(j, i); Soilder tempSoilder = new Soilder(Soilder.Group.White, tempPossition); InsertSoilder(tempSoilder); } } else { if (j % 2 == 0) { Possition tempPossition = new Possition(j, i); Soilder tempSoilder = new Soilder(Soilder.Group.White, tempPossition); InsertSoilder(tempSoilder); } } } } }
private List <Move> createWhitePlayerEatingMoves(Soilder i_Mover) { Move newLegalMove; //an empty list to hold possible moves List <Move> moves = new List <Move>(); //create the two possible possitions in the right diriction and possions of the victim Possition double_right_down = new Possition((int)i_Mover.m_Possition.m_Column + 2, (int)i_Mover.m_Possition.m_Row + 2); Possition double_left_down = new Possition((int)i_Mover.m_Possition.m_Column - 2, (int)i_Mover.m_Possition.m_Row + 2); Possition victem_right_down = new Possition((int)i_Mover.m_Possition.m_Column + 1, (int)i_Mover.m_Possition.m_Row + 1); Possition victem_left_down = new Possition((int)i_Mover.m_Possition.m_Column - 1, (int)i_Mover.m_Possition.m_Row + 1); //check in both directions that the wanted square is empty on board , that victem existis, and is of a different group if (possitionOnBoardAndEmpty(double_right_down, m_Size) && //if the sqare is on the board and free (soilderAt(victem_right_down) != null) && //if the victim sqare is not null (i_Mover.Team != soilderAt(victem_right_down).Team)) //if the victem is of a differnt team { newLegalMove = new Move(i_Mover.m_Possition, double_right_down, true); //set as eating move moves.Add(newLegalMove); } if (possitionOnBoardAndEmpty(double_left_down, m_Size) && //if the sqare is on the board and free (soilderAt(victem_left_down) != null) && //if the victim sqare is not null (i_Mover.Team != soilderAt(victem_left_down).Team)) //if the victem is of a differnt team { newLegalMove = new Move(i_Mover.m_Possition, double_left_down, true); //set as eating move moves.Add(newLegalMove); } return(moves); }
public void DeleteSoilder(Soilder i_Soilder) { //removing soilder from the correct list if (i_Soilder.Team == Soilder.Group.Black) { m_BlackSoilders.Remove(i_Soilder); } else { m_WhiteSoilders.Remove(i_Soilder); } m_board[(int)i_Soilder.Possition.m_Row, (int)i_Soilder.Possition.m_Column] = null; }
public void InsertSoilder(Soilder i_Soilder) { //adding soilder to the correct list if (i_Soilder.Team == Soilder.Group.Black) { m_BlackSoilders.Add(i_Soilder); } else { m_WhiteSoilders.Add(i_Soilder); } //adding soilder to the board m_board[(int)i_Soilder.Possition.m_Row, (int)i_Soilder.Possition.m_Column] = i_Soilder; }
public List <Move> getVaildMoves(Soilder i_Mover) { List <Move> validMovesForOnePeice = new List <Move>(); if (i_Mover.Team == Soilder.Group.White || i_Mover.IsKing == true) //if the mover is king color doesnt matter { validMovesForOnePeice.AddRange(createWhitePlayerMoves(i_Mover)); validMovesForOnePeice.AddRange(createWhitePlayerEatingMoves(i_Mover)); } if (i_Mover.Team == Soilder.Group.Black || i_Mover.IsKing == true) { validMovesForOnePeice.AddRange(createBlackPlayerMoves(i_Mover)); validMovesForOnePeice.AddRange(createBlackPlayerEatingMoves(i_Mover)); } validMovesForOnePeice = fillterMoves(validMovesForOnePeice); //if one of the moves is an eating move remove all non eating moves return(validMovesForOnePeice); }
private List <Move> createBlackPlayerMoves(Soilder i_Mover) { Move newLegalMove; List <Move> moves = new List <Move>(); //an empty list to hold possible moves //create the two possible possitions in the right diriction Possition right_up = new Possition((int)i_Mover.m_Possition.m_Column + 1, (int)i_Mover.m_Possition.m_Row - 1); Possition left_up = new Possition((int)i_Mover.m_Possition.m_Column - 1, (int)i_Mover.m_Possition.m_Row - 1); //check in both directions that the wanted square is empty if (possitionOnBoardAndEmpty(right_up, m_Size)) { newLegalMove = new Move(i_Mover.m_Possition, right_up, false);//set as not eating move moves.Add(newLegalMove); } if (possitionOnBoardAndEmpty(left_up, m_Size)) { newLegalMove = new Move(i_Mover.m_Possition, left_up, false);//set as not eating move moves.Add(newLegalMove); } return(moves); }
private string checkForPlayingPiece(int i_Row, int i_Column) { string sqaure; if (m_board[i_Row, i_Column] != null) { Soilder target = this.m_board[i_Row, i_Column]; if (target.Team == Soilder.Group.Black) { if (target.IsKing) { sqaure = "K"; } else { sqaure = "X"; } } else { if (target.IsKing) { sqaure = "U"; } else { sqaure = "O"; } } } else { sqaure = " "; } return(sqaure); }
public void startGame() { //create user interface UserInterface userInterface = new UserInterface(); //welcome message userInterface.GameEntry(); //initealize player String playerName = userInterface.getPlayerName(); this.player1 = new Player(playerName, false, Soilder.Group.Black); //get board size int boardSize = userInterface.getSizeOfBoard(); //set player two if (userInterface.isPlayer2Computer()) { player2 = new Player("computer", true, Soilder.Group.White); } else { player2 = new Player(userInterface.getPlayerName(), false, Soilder.Group.White); } this.endtournemnetCondision = false; while (!endtournemnetCondision) { //start the board - needs to move to constractor this.playingBoard = new CheckersBoard(boardSize); playingBoard.InitWhiteTeam(); playingBoard.InitBlackTeam(); this.endGameCondision = false; this.turn = player1; this.prevTurn = player2; //start the game Move PlayerMove = new Move(); Boolean firstMove = true; while (!endGameCondision) //change to do while { //print cuurent sqreen - first time move is empty userInterface.upDateOutPut(playingBoard, prevTurn, previosMove, turn, firstMove); firstMove = false; Boolean stopTheGame = false; //in case the user wants to quit and can List <Move> currentValidMoves = new List <Move>(); if (this.turn.m_Group == Soilder.Group.Black) { currentValidMoves = this.playingBoard.getAllVaildTeamMoves(playingBoard.m_BlackSoilders); } else { currentValidMoves = this.playingBoard.getAllVaildTeamMoves(playingBoard.m_WhiteSoilders); } //if the current player is a computer use AI class if (turn.m_IsComputer) { PlayerMove = AI.GenerateRandomMove(currentValidMoves); } else { PlayerMove = userInterface.getValidMoveFromUser(currentValidMoves); //if user want out move is an empty move while (userInterface.m_UserWantsToQuit) //uses a public flag to check -maybe we will need to change this { if (checkIfPlayerCanQuit(turn)) //a gamemaneger methode to calculate score { stopTheGame = true; userInterface.m_UserWantsToQuit = false; //set the flag back to false for next game break; } else { userInterface.notifyPlayer("You can not quit because you have more or the same number of points "); userInterface.m_UserWantsToQuit = false; //set the flag back to false PlayerMove = userInterface.getValidMoveFromUser(currentValidMoves); } } } if (stopTheGame) { break; //end the game and go to score calculation } //move with move or eat if (PlayerMove.m_IsEatingMove) { playingBoard.Eat(PlayerMove); //if last move has more eating moves if it does eat again Boolean stillEating = true; while (stillEating) { Soilder eatingSoilder = playingBoard.soilderAt(PlayerMove.m_To); List <Move> PossibleEatingMoves = playingBoard.getVaildMoves(eatingSoilder); if (PossibleEatingMoves.Count != 0) { if (PossibleEatingMoves.First().m_IsEatingMove) { userInterface.upDateOutPut(playingBoard, turn, PlayerMove, turn, firstMove); //print the same turn PlayerMove = userInterface.getValidMoveFromUser(PossibleEatingMoves); playingBoard.Eat(PlayerMove); } else { stillEating = false; } } else { stillEating = false; } } } else { playingBoard.Move(PlayerMove); } //up date score upDateScore(); //up date winning condision upDateEndGameCondision(); //turn change swapTurns(PlayerMove); } //game ended Player winner = player1; Boolean teko = false; if (player1.m_Score < player2.m_Score) { winner = player2; } if (player1.m_Score == player2.m_Score) { teko = true; } userInterface.endOfGame(player1, player2, winner, teko); //update overall score and ask user if he wants to continue upDateOverAllScore(); //this also resets game score if (!userInterface.wantAnotherGame()) { endtournemnetCondision = true; } } //end of over all game - send user final result and termenate program Player bigWinner = player1; Boolean draw = false; if (player1.m_OverAllScore < player2.m_OverAllScore) { bigWinner = player2; } if (player1.m_OverAllScore == player2.m_OverAllScore) { draw = true; } userInterface.endOftournament(player1, player2, bigWinner, draw); Console.WriteLine("press any key to exit"); Console.Read(); }