public void Flying(int input, int inputTo) { if (Current_Player.MoveFlying(input, inputTo, board, referee, Current_Phase)) { if (board.areNewMills(Current_Player.Color)) { Current_Phase = Phase.Killing; } SwitchPlayer(); } }
//I've done it this way to prevent a loop when asking for input. For testing purposes // Needs additional printing functionallity private void DoPlacePhase(int input) { if (Current_Player.Place(input, board, referee, Current_Phase)) { if (board.areNewMills(Current_Player.Color)) { Current_Phase = Phase.Killing; } else if (box.IsEmpty()) { Current_Phase = Phase.Moving; SwitchPlayer(); return; } else { SwitchPlayer(); } } }
private void DoKillPhase(int input) { if (Current_Player.Kill(input, board, referee)) { if (Current_Player.IsWinner(board, oppositionColor())) { Current_Phase = Phase.Winning; } else if (box.IsEmpty()) { SwitchPlayer(); Current_Phase = Phase.Moving; return; } else { SwitchPlayer(); Current_Phase = Phase.Placing; } } }
private void DoMovePhase(int input) { if (Current_Player.Select(input, board, referee)) { int inputTo = External.MoveToInput(); // We might need to move this for testing but lets see how it goes if (board.numPlayerCowsOnBoard(Current_Player.Color) == 3) // If flying { Flying(input, inputTo); } else if (Current_Player.Move(input, inputTo, board, referee, Current_Phase)) { if (board.areNewMills(Current_Player.Color)) { Current_Phase = Phase.Killing; } else { SwitchPlayer(); } } } }
/// <summary> /// Checks if any pawn must be eliminated. /// </summary> /// <param name="m_Square">The clicked square (new position of a moved pawn). </param> /// <param name="m_board">Dictionnary containing the actual board state.</param> /// <returns> Returns a list containing the name of the eliminated pawns.</returns> public List <String> search_Eliminated_Pawn(Square m_Square, Dictionary <string, Square> m_board) { List <string> eliminated_Pawn = new List <string>(); //Store the position of the square. int column = int.Parse(m_Square.Name.Substring(m_Square.Name.Length - 2, 1)); int row = int.Parse(m_Square.Name.Substring(m_Square.Name.Length - 1, 1)); #region Elimination conditions if (Current_Player.Role == Player_Role.Attacker) { //checks if there is any adjacent enemy pawn and if the elimination condition if filled. //(Surrounded by two pawns vertically or horizontally) //Top if (row > 1) { if (m_board[column + "" + (row - 1)].Occupant == Occupant.Defender && m_board[column + "" + (row - 2)].Occupant == Occupant.Attacker) { eliminated_Pawn.Add(m_board[column + "" + (row - 1)].Name); } } //Right if (column < 7) { if (m_board[(column + 1) + "" + row].Occupant == Occupant.Defender && m_board[(column + 2) + "" + row].Occupant == Occupant.Attacker) { eliminated_Pawn.Add(m_board[(column + 1) + "" + row].Name); } } //Bottom if (row < 7) { if (m_board[column + "" + (row + 1)].Occupant == Occupant.Defender && m_board[column + "" + (row + 2)].Occupant == Occupant.Attacker) { eliminated_Pawn.Add(m_board[column + "" + (row + 1)].Name); } } //Left if (column > 1) { if (m_board[(column - 1) + "" + row].Occupant == Occupant.Defender && m_board[(column - 2) + "" + row].Occupant == Occupant.Attacker) { eliminated_Pawn.Add(m_board[(column - 1) + "" + row].Name); } } //Checking if the King is captured (surrounded by 4 attacker or throne + 3 attacker) //Getting king positions string king_Key = m_board.FirstOrDefault(x => x.Value.Occupant == Occupant.King).Key; column = int.Parse(m_board[king_Key].Name.Substring(m_board[king_Key].Name.Length - 2, 1)); row = int.Parse(m_board[king_Key].Name.Substring(m_board[king_Key].Name.Length - 1, 1)); //If the king has a sufficient space around him to be surrounded if (column > 0 && column < 8 && row > 0 && row < 8) { //Checking top && bottom if ((m_board[column + "" + (row + 1)].Occupant == Occupant.Attacker || m_board[column + "" + (row + 1)] == m_board["44"]) && (m_board[column + "" + (row - 1)].Occupant == Occupant.Attacker || m_board[column + "" + (row - 1)] == m_board["44"])) { //Checking right and left if ((m_board[(column + 1) + "" + row].Occupant == Occupant.Attacker || m_board[(column + 1) + "" + row] == m_board["44"]) && (m_board[(column - 1) + "" + row].Occupant == Occupant.Attacker || m_board[(column - 1) + "" + row] == m_board["44"])) { eliminated_Pawn.Add(m_board[column + "" + row].Name); this.Over = true; } } } } else if (Current_Player.Role == Player_Role.Defender) { //checks if there is any adjacent enemy pawn and if the elimination condition if filled //Top if (row > 1) { if (m_board[column + "" + (row - 1)].Occupant == Occupant.Attacker && (m_board[column + "" + (row - 2)].Occupant == Occupant.Defender || m_board[column + "" + (row - 2)].Occupant == Occupant.King)) { eliminated_Pawn.Add(m_board[column + "" + (row - 1)].Name); } } //Right if (column < 7) { if (m_board[(column + 1) + "" + row].Occupant == Occupant.Attacker && (m_board[(column + 2) + "" + row].Occupant == Occupant.Defender || m_board[(column + 2) + "" + row].Occupant == Occupant.King)) { eliminated_Pawn.Add(m_board[(column + 1) + "" + row].Name); } } //Bottom if (row < 7) { if (m_board[column + "" + (row + 1)].Occupant == Occupant.Attacker && (m_board[column + "" + (row + 2)].Occupant == Occupant.Defender || m_board[column + "" + (row + 2)].Occupant == Occupant.King)) { eliminated_Pawn.Add(m_board[column + "" + (row + 1)].Name); } } //Left if (column > 1) { if (m_board[(column - 1) + "" + row].Occupant == Occupant.Attacker && (m_board[(column - 2) + "" + row].Occupant == Occupant.Defender || m_board[(column - 2) + "" + row].Occupant == Occupant.King)) { eliminated_Pawn.Add(m_board[(column - 1) + "" + row].Name); } } //Checking if the King captured himself (going into 3 enemies and neighboring the throne). if (m_Square.Occupant == Occupant.King) { //If the king has a sufficient space around him to be surrounded if (column > 0 && column < 8 && row > 0 && row < 8) { //Checking top && bottom if ((m_board[column + "" + (row + 1)].Occupant == Occupant.Attacker || m_board[column + "" + (row + 1)] == m_board["44"]) && (m_board[column + "" + (row - 1)].Occupant == Occupant.Attacker || m_board[column + "" + (row - 1)] == m_board["44"])) { //Checking right and left if ((m_board[(column + 1) + "" + row].Occupant == Occupant.Attacker || m_board[(column + 1) + "" + row] == m_board["44"]) && (m_board[(column - 1) + "" + row].Occupant == Occupant.Attacker || m_board[(column - 1) + "" + row] == m_board["44"])) { eliminated_Pawn.Add(m_board[column + "" + row].Name); Current_Player = Attacker; this.Over = true; } } } } } #endregion Elimination conditions //Update players statistics if (eliminated_Pawn.Count > 0) { Current_Player.add_Enemy_Pawn_Eliminated(eliminated_Pawn.Count); if (Current_Player.Role == Player_Role.Attacker) { Defender.remove_Pawn(eliminated_Pawn.Count); } else { Attacker.remove_Pawn(eliminated_Pawn.Count); } } return(eliminated_Pawn); }