private static IEnumerable<Point> GetPossibleMoves(Maze previousMaze) { var previousCoordinate = previousMaze.FindCoordinateOf(Properties.Settings.Default.SymbolPlayerA); var moveList = new List<Point>(); if (previousCoordinate.Y + 1 < Properties.Settings.Default.MazeWidth) if (!previousMaze.GetSymbol(previousCoordinate.X, previousCoordinate.Y + 1).Equals(Properties.Settings.Default.SymbolWall) && !WasInRespawnEntranceA(previousCoordinate.X, previousCoordinate.Y)) moveList.Add(new Point(previousCoordinate.X, previousCoordinate.Y + 1)); if (previousCoordinate.Y - 1 >= 0) if (!previousMaze.GetSymbol(previousCoordinate.X, previousCoordinate.Y - 1).Equals(Properties.Settings.Default.SymbolWall) && !WasInRespawnEntranceB(previousCoordinate.X, previousCoordinate.Y)) moveList.Add(new Point(previousCoordinate.X, previousCoordinate.Y - 1)); if (previousCoordinate.X + 1 < Properties.Settings.Default.MazeHeight) if (!previousMaze.GetSymbol(previousCoordinate.X + 1, previousCoordinate.Y).Equals(Properties.Settings.Default.SymbolWall) && !WasInRespawnZone(previousCoordinate.X, previousCoordinate.Y)) moveList.Add(new Point(previousCoordinate.X + 1, previousCoordinate.Y)); if (previousCoordinate.X - 1 >= 0) if (!previousMaze.GetSymbol(previousCoordinate.X - 1, previousCoordinate.Y).Equals(Properties.Settings.Default.SymbolWall) && !WasInRespawnZone(previousCoordinate.X, previousCoordinate.Y)) moveList.Add(new Point(previousCoordinate.X - 1, previousCoordinate.Y)); if (previousCoordinate.X.Equals(Properties.Settings.Default.MazeHeight / 2 - 1) && previousCoordinate.Y.Equals(Properties.Settings.Default.MazeWidth - 1)) moveList.Add(new Point(Properties.Settings.Default.MazeHeight / 2 - 1, 0)); if (previousCoordinate.X.Equals(Properties.Settings.Default.MazeHeight / 2 - 1) && previousCoordinate.Y.Equals(0)) moveList.Add(new Point(Properties.Settings.Default.MazeHeight / 2 - 1, Properties.Settings.Default.MazeWidth - 1)); return moveList; }
public Game(Player playerA, Player playerB, String pathToInitialMaze) { _playerPool = new PlayerPool(playerA, playerB); _maze = new Maze(pathToInitialMaze); _gameMarshaller = new GameMarshaller(); _iteration = 1; _secondMazePlayer = 'A'; }
public static Enums.MazeValidationOutcome ValidateMaze(Maze currentMaze, Maze previousMaze) { if (!IsMazeValid(currentMaze, previousMaze)) return Enums.MazeValidationOutcome.InvalidMazeTooManyChanges; if(!IsPossibleMoveMade(currentMaze, previousMaze)) return Enums.MazeValidationOutcome.InvalidMazeIllegalMoveMade; return (int)Enums.MazeValidationOutcome.ValidMaze; }
public static Enums.MazeValidationOutcome ValidateMaze(Maze currentMaze, Maze previousMaze, StreamWriter logFile) { if (!IsMazeValid(currentMaze, previousMaze, logFile)) return Enums.MazeValidationOutcome.InvalidMazeTooManyChanges; if(!IsPossibleMoveMade(currentMaze, previousMaze)) return Enums.MazeValidationOutcome.InvalidMazeIllegalMoveMade; if (IsPillDroppedInRespawnZone(currentMaze, previousMaze)) return Enums.MazeValidationOutcome.InvalidMazePillDroppedInRespawnZone; return (int)Enums.MazeValidationOutcome.ValidMaze; }
public Enums.GameOutcome ProcessGame(Maze maze, Enums.TurnOutcome turnOutcome) { ProcessTurnOutcome(turnOutcome); if (IsOutOfPills(maze)) return Enums.GameOutcome.OutOfPills; if (_numberOfTurnsWithNoPointsGained > Properties.Settings.Default.SettingMaxTurnsWithNoPointsScored) return Enums.GameOutcome.NoScoringMaxed; return Enums.GameOutcome.ProceedToNextRound; }
public Maze GetMove(Maze maze, String outputFilePath, StreamWriter logFile) { var playerOutputFilePath = _workingPath + "\\" + Properties.Settings.Default.SettingBotOutputFileName; File.Delete(playerOutputFilePath); var startTime = DateTime.Now; var p = new Process { StartInfo = { WorkingDirectory = _workingPath, FileName = _workingPath + "\\" + _executableFileName, Arguments = "\"" + outputFilePath + "\"" + " >> botlogs_capture.txt 2>&1", CreateNoWindow = true, WindowStyle = ProcessWindowStyle.Hidden } }; p.Start(); try { startTime = p.StartTime; // Adjust for actual start time of process } catch (Exception ex) { Console.WriteLine(ex.ToString()); } var attemptFetchingMaze = true; while (attemptFetchingMaze) { if (File.Exists(playerOutputFilePath)) { Thread.Sleep(50); // Allow file write to complete, otherwise might get permission exception or corrupt file if (!p.HasExited) p.Kill(); try { var mazeFromPlayer = new Maze(playerOutputFilePath); return mazeFromPlayer; } catch (UnreadableMazeException e) { Console.WriteLine(e.ToString()); logFile.WriteLine("[GAME] : Unreadable maze from player " + _playerName); } } if ((DateTime.Now - startTime).TotalSeconds > Properties.Settings.Default.SettingBotOutputTimeoutSeconds) { attemptFetchingMaze = false; if (!p.HasExited) p.Kill(); logFile.WriteLine("[GAME] : Timeout from player " + _playerName); } Thread.Sleep(100); } return null; }
private static int GetNumberOfDifferences(Maze currentMaze, Maze previousMaze) { var difference = 0; for (var x = 0; x < Properties.Settings.Default.MazeHeight; x++) { for (var y = 0; y < Properties.Settings.Default.MazeWidth; y++) { if (currentMaze.GetSymbol(x, y) != previousMaze.GetSymbol(x, y)) difference++; } } return difference; }
public Maze(Maze maze) { _map = new char[Properties.Settings.Default.MazeHeight][]; for (var x = 0; x < Properties.Settings.Default.MazeHeight; x++) { var row = new char[Properties.Settings.Default.MazeWidth]; for (var y = 0; y < Properties.Settings.Default.MazeWidth; y++) { row[y] = maze.GetSymbol(x,y); } _map[x] = row; } }
private static IEnumerable<Point> GetPossibleMoves(Maze previousMaze) { var previousCoordinate = previousMaze.FindCoordinateOf(Symbols.SYMBOL_PLAYER_A); var opponentCoordinate = previousMaze.FindCoordinateOf(Symbols.SYMBOL_PLAYER_B); var moveList = new List<Point>(); // Right if (previousCoordinate.Y + 1 < Properties.Settings.Default.MazeWidth) if (previousMaze.GetSymbol(previousCoordinate.X, previousCoordinate.Y + 1) != Symbols.SYMBOL_WALL && !WasInRespawnPoint(previousCoordinate.X, previousCoordinate.Y)) moveList.Add(new Point(previousCoordinate.X, previousCoordinate.Y + 1)); // Left if (previousCoordinate.Y - 1 >= 0) if (previousMaze.GetSymbol(previousCoordinate.X, previousCoordinate.Y - 1) != Symbols.SYMBOL_WALL && !WasInRespawnPoint(previousCoordinate.X, previousCoordinate.Y)) moveList.Add(new Point(previousCoordinate.X, previousCoordinate.Y - 1)); // Down if (previousCoordinate.X + 1 < Properties.Settings.Default.MazeHeight) if (previousMaze.GetSymbol(previousCoordinate.X + 1, previousCoordinate.Y) != Symbols.SYMBOL_WALL && !WasInRespawnEntranceA(previousCoordinate.X, previousCoordinate.Y) && !WasInRespawnPoint(previousCoordinate.X + 1, previousCoordinate.Y) && // Opponent cannot be eaten while in the respawn zone. (!WasInRespawnZone(opponentCoordinate.X, opponentCoordinate.Y) || previousCoordinate.Y!=opponentCoordinate.Y || previousCoordinate.X + 1!=opponentCoordinate.X)) moveList.Add(new Point(previousCoordinate.X + 1, previousCoordinate.Y)); // Up if (previousCoordinate.X - 1 >= 0) if (previousMaze.GetSymbol(previousCoordinate.X - 1, previousCoordinate.Y) != Symbols.SYMBOL_WALL && !WasInRespawnEntranceB(previousCoordinate.X, previousCoordinate.Y) && !WasInRespawnPoint(previousCoordinate.X - 1, previousCoordinate.Y) && // Opponent cannot be eaten while in the respawn zone. (!WasInRespawnZone(opponentCoordinate.X, opponentCoordinate.Y) || previousCoordinate.Y!=opponentCoordinate.Y || previousCoordinate.X - 1!=opponentCoordinate.X)) moveList.Add(new Point(previousCoordinate.X - 1, previousCoordinate.Y)); // Wrap right if (previousCoordinate.X == (Properties.Settings.Default.MazeHeight / 2 - 1) && previousCoordinate.Y == (Properties.Settings.Default.MazeWidth - 1)) moveList.Add(new Point(Properties.Settings.Default.MazeHeight / 2 - 1, 0)); // Wrap left if (previousCoordinate.X == (Properties.Settings.Default.MazeHeight / 2 - 1) && previousCoordinate.Y == 0) moveList.Add(new Point(Properties.Settings.Default.MazeHeight / 2 - 1, Properties.Settings.Default.MazeWidth - 1)); return moveList; }
public Maze GetMove(Maze maze, String outputFilePath, StreamWriter logFile) { var playerOutputFilePath = _workingPath + "\\" + Properties.Settings.Default.SettingBotOutputFileName; File.Delete(playerOutputFilePath); var startTime = DateTime.Now; var p = new Process { StartInfo = { WorkingDirectory = _workingPath, FileName = _executableFileName, Arguments = "\"" + outputFilePath + "\"", CreateNoWindow = true, WindowStyle = ProcessWindowStyle.Hidden } }; p.Start(); var attemptFetchingMaze = true; while (attemptFetchingMaze) { if (File.Exists(playerOutputFilePath)) { if(!p.HasExited) p.Kill(); try { var mazeFromPlayer = new Maze(playerOutputFilePath); return mazeFromPlayer; } catch (UnreadableMazeException e) { Console.WriteLine(e.ToString()); logFile.WriteLine("[GAME] : Unreadable maze from player " + _playerName); } } if ((DateTime.Now - startTime).TotalSeconds > Properties.Settings.Default.SettingBotOutputTimeoutSeconds) { attemptFetchingMaze = false; if (!p.HasExited) p.Kill(); logFile.WriteLine("[GAME] : Timeout from player " + _playerName); } Thread.Sleep(100); } return null; }
public static Enums.TurnOutcome ProcessMove(Maze currentMaze, Maze previousMaze, Point currentPosition, Point previousPosition, Point opponentPosition, Player currentPlayer) { currentPlayer.SetCurrentPosition(currentPosition); if (IsMoveMadeAndScoredPoint(previousMaze, currentPosition)) { currentPlayer.AddToScore(Properties.Settings.Default.SettingPointsPerPill); return Enums.TurnOutcome.MoveMadeAndPointScored; } if (IsMoveMadeAndScoredBonusPoint(previousMaze, currentPosition)) { currentPlayer.AddToScore(Properties.Settings.Default.SettingPointsPerBonusPill); return Enums.TurnOutcome.MoveMadeAndBonusPointScored; } if (IsMoveMadeAndDiedFromPoisonPill(previousMaze, currentPosition)) { currentMaze.SetSymbol(currentPosition.X, currentPosition.Y, Symbols.SYMBOL_EMPTY); currentMaze.SetSymbol(Properties.Settings.Default.MazeCenterX, Properties.Settings.Default.MazeCenterY, Symbols.SYMBOL_PLAYER_A); return Enums.TurnOutcome.MoveMadeAndDiedFromPoisonPill; } if (IsMoveMadeAndKilledOpponent(currentPosition, opponentPosition)) { currentMaze.SetSymbol(Properties.Settings.Default.MazeCenterX, Properties.Settings.Default.MazeCenterY, Symbols.SYMBOL_PLAYER_B); return Enums.TurnOutcome.MoveMadeAndKilledOpponent; } if (IsMoveMadeAndDroppedPoisonPill(currentMaze, previousPosition)) { if (!currentPlayer.IsAllowedPoisonPillDrop()) return Enums.TurnOutcome.MoveMadeAndDroppedPoisonPillIllegally; currentPlayer.UsePoisonPill(); return Enums.TurnOutcome.MoveMadeAndDroppedPoisonPill; } return (int)Enums.TurnOutcome.MoveMade; }
private Enums.MazeValidationOutcome GetMazeValidationOutcome(StreamWriter logFile, Maze mazeFromPlayer) { logFile.WriteLine("[GAME] : Received maze from player " + _currentPlayer.GetPlayerName()); var mazeValidationOutcome = (MazeValidator.ValidateMaze(mazeFromPlayer, _maze, logFile)); logFile.WriteLine("[MAZE] : " + mazeValidationOutcome); return(mazeValidationOutcome); }
public GameResult Run(String folderPath) { var gamePlayDirectoryPath = Path.Combine(Environment.CurrentDirectory, folderPath); Directory.CreateDirectory(gamePlayDirectoryPath); var outputFilePath = Path.Combine(gamePlayDirectoryPath, Properties.Settings.Default.SettingGamePlayFile); _maze.WriteMaze(outputFilePath); Player winner = null; var gameOutcome = Enums.GameOutcome.ProceedToNextRound; Directory.CreateDirectory(folderPath); Directory.CreateDirectory(Path.Combine(folderPath, Properties.Settings.Default.SettingReplayFolder)); var logFile = new StreamWriter(Path.Combine(folderPath, Properties.Settings.Default.SettingMatchLogFileName)); CreateIterationStateFile(folderPath); logFile.WriteLine("[GAME] : Match started"); _iteration++; while (gameOutcome == Enums.GameOutcome.ProceedToNextRound) { _currentPlayer = _playerPool.GetNextPlayer(); var mazeFromPlayer = _currentPlayer.GetMove(_maze, Path.Combine(gamePlayDirectoryPath, Properties.Settings.Default.SettingGamePlayFile), logFile); if (mazeFromPlayer != null) { var mazeValidationOutcome = GetMazeValidationOutcome(logFile, mazeFromPlayer); if (mazeValidationOutcome == Enums.MazeValidationOutcome.ValidMaze) { var opponentPosition = _maze.FindCoordinateOf(Symbols.SYMBOL_PLAYER_B); var previousPosition = _maze.FindCoordinateOf(Symbols.SYMBOL_PLAYER_A); var currentPosition = mazeFromPlayer.FindCoordinateOf(Symbols.SYMBOL_PLAYER_A); var turnOutcome = GetTurnOutcome(mazeFromPlayer, currentPosition, previousPosition, opponentPosition, logFile); if (turnOutcome != Enums.TurnOutcome.MoveMadeAndDroppedPoisonPillIllegally) { RegenerateOpponentIfDead(opponentPosition, mazeFromPlayer); gameOutcome = GetGameOutcome(mazeFromPlayer, logFile, gameOutcome, turnOutcome); winner = DetermineIfWinner(gameOutcome, winner); } else { gameOutcome = ProcessIllegalMove(logFile, gameOutcome, ref winner); } } else { gameOutcome = ProcessIllegalMove(logFile, gameOutcome, ref winner); } _maze = mazeFromPlayer; _maze.SwapPlayerSymbols(); _maze.WriteMaze(Path.Combine(gamePlayDirectoryPath, Properties.Settings.Default.SettingGamePlayFile)); Maze iterationFileMaze = CreateIterationStateFile(folderPath); _iteration++; foreach (var player in _playerPool.GetPlayers()) { Console.Write(player.GetSymbol() + "," + player.GetPlayerName() + ": " + player.GetScore() + " "); } Console.WriteLine(); iterationFileMaze.Print(); } else { gameOutcome = ProcessIllegalMove(logFile, gameOutcome, ref winner); } } CreateMatchInfo(gameOutcome, winner, logFile); logFile.Close(); var replayMatchOutcome = new StreamWriter(Path.Combine(folderPath, "replay", "matchinfo.out")); CreateMatchInfo(gameOutcome, winner, replayMatchOutcome); replayMatchOutcome.Close(); return(new GameResult { Players = _playerPool.GetPlayers(), Outcome = gameOutcome, Iterations = _iteration - 1, Folder = folderPath }); }
private Enums.TurnOutcome GetTurnOutcome(Maze mazeFromPlayer, Point currentPosition, Point previousPosition, Point opponentPosition, StreamWriter logFile) { var turnOutcome = TurnMarshaller.ProcessMove(mazeFromPlayer, _maze, currentPosition, previousPosition, opponentPosition, _currentPlayer); logFile.WriteLine("[TURN] : " + turnOutcome); logFile.WriteLine("[TURN] : " + _currentPlayer.GetPlayerName() + " at " + currentPosition.X + ", " + currentPosition.Y); return turnOutcome; }
private static Boolean IsPossibleMoveMade(Maze currentMaze, Maze previousMaze) { var currentPosition = currentMaze.FindCoordinateOf(Properties.Settings.Default.SymbolPlayerA); return GetPossibleMoves(previousMaze).Any(coordinate => coordinate.X.Equals(currentPosition.X) && coordinate.Y.Equals(currentPosition.Y)); }
public static bool IsOutOfPills(Maze maze) { var flatFormatMaze = maze.ToFlatFormatString(); return !(flatFormatMaze.Contains(Symbols.SYMBOL_PILL) || flatFormatMaze.Contains(Symbols.SYMBOL_BONUS_PILL)); }
private static bool IsMoveMadeAndDroppedPoisonPill(Maze currentMaze, Point previousPosition) { return currentMaze.GetSymbol(previousPosition.X, previousPosition.Y) == Symbols.SYMBOL_POISON_PILL; }
private static void RegenerateOpponentIfDead(Point opponentPosition, Maze mazeFromPlayer) { if (opponentPosition.IsEmpty) mazeFromPlayer.SetSymbol(Properties.Settings.Default.MazeCenterX, Properties.Settings.Default.MazeCenterY, Symbols.SYMBOL_PLAYER_B); }
private static bool IsMoveMadeAndDroppedPoisonPill(Maze currentMaze, Point previousPosition) { return currentMaze.GetSymbol(previousPosition.X, previousPosition.Y).Equals(Properties.Settings.Default.SymbolPoisonPill); }
private static bool IsPillDroppedInRespawnZone(Maze currentMaze, Maze previousMaze) { var previousCoordinateA = previousMaze.FindCoordinateOf(Symbols.SYMBOL_PLAYER_A); if (currentMaze.GetSymbol(previousCoordinateA) == Symbols.SYMBOL_POISON_PILL) return WasInRespawnZone(previousCoordinateA.X, previousCoordinateA.Y); return false; }
private static bool IsMazeValid(Maze currentMaze, Maze previousMaze, StreamWriter logFile) { var diffs = GetNumberOfDifferences(currentMaze, previousMaze); if (diffs == _EXACT_NUMBER_OF_DIFFERENCES_FOR_LEGAL_MOVE) return true; logFile.WriteLine("[Validator] : Failure: Number of changes is: " + diffs); return false; }
public Maze GetMove(Maze maze, String outputFilePath, StreamWriter logFile) { var playerOutputFilePath = _workingPath + System.IO.Path.DirectorySeparatorChar + Properties.Settings.Default.SettingBotOutputFileName; File.Delete(playerOutputFilePath); var processName = _workingPath + System.IO.Path.DirectorySeparatorChar + _executableFileName; var arguments = "\"" + outputFilePath + "\""; if (Environment.OSVersion.Platform == PlatformID.Unix) { arguments = processName + " " + arguments; processName = "/bin/bash"; } var p = new Process { StartInfo = { WorkingDirectory = _workingPath, FileName = processName, Arguments = arguments, CreateNoWindow = true, WindowStyle = ProcessWindowStyle.Hidden, UseShellExecute = false, RedirectStandardOutput = true, RedirectStandardError = true } }; System.Diagnostics.DataReceivedEventHandler h = (sender, args) => { if (!String.IsNullOrEmpty(args.Data)) { using (System.IO.StreamWriter file = new System.IO.StreamWriter(_workingPath + System.IO.Path.DirectorySeparatorChar + "botlogs_capture.txt", true)) { file.WriteLine(args.Data); } } }; p.OutputDataReceived += h; p.ErrorDataReceived += h; p.Start(); p.BeginOutputReadLine(); p.BeginErrorReadLine(); bool didExit = p.WaitForExit(Properties.Settings.Default.SettingBotOutputTimeoutSeconds * 1000); if (!didExit) { p.Kill(); logFile.WriteLine("[GAME] : Killed process " + processName); } if (p.ExitCode != 0) { logFile.WriteLine("[GAME] : Process exited " + p.ExitCode + " from player " + _playerName); } if (!File.Exists(playerOutputFilePath)) { logFile.WriteLine("[GAME] : No output file from player " + _playerName); return null; } try { var mazeFromPlayer = new Maze(playerOutputFilePath); return mazeFromPlayer; } catch (UnreadableMazeException e) { Console.WriteLine(e.ToString()); logFile.WriteLine("[GAME] : Unreadable maze from player: " + _playerName); } return null; }
public Maze GetMove(Maze maze, String outputFilePath, StreamWriter logFile) { var playerOutputFilePath = _workingPath + System.IO.Path.DirectorySeparatorChar + Properties.Settings.Default.SettingBotOutputFileName; File.Delete(playerOutputFilePath); var startTime = DateTime.Now; var p = new Process { StartInfo = { WorkingDirectory = _workingPath, FileName = _workingPath + System.IO.Path.DirectorySeparatorChar + _executableFileName, Arguments = "\"" + outputFilePath + "\"" + " >> botlogs_capture.txt 2>&1", CreateNoWindow = true, WindowStyle = ProcessWindowStyle.Hidden } }; p.Start(); try { startTime = p.StartTime; // Adjust for actual start time of process } catch (Exception ex) { Console.WriteLine(ex.ToString()); } var attemptFetchingMaze = true; while (attemptFetchingMaze) { if (File.Exists(playerOutputFilePath)) { Thread.Sleep(50); // Allow file write to complete, otherwise might get permission exception or corrupt file if (!p.HasExited) { p.Kill(); } try { var mazeFromPlayer = new Maze(playerOutputFilePath); return(mazeFromPlayer); } catch (UnreadableMazeException e) { Console.WriteLine(e.ToString()); logFile.WriteLine("[GAME] : Unreadable maze from player " + _playerName); } } if ((DateTime.Now - startTime).TotalSeconds > Properties.Settings.Default.SettingBotOutputTimeoutSeconds) { attemptFetchingMaze = false; if (!p.HasExited) { p.Kill(); } logFile.WriteLine("[GAME] : Timeout from player " + _playerName); } Thread.Sleep(100); } return(null); }
private static Boolean IsPossibleMoveMade(Maze currentMaze, Maze previousMaze) { var currentPosition = currentMaze.FindCoordinateOf(Symbols.SYMBOL_PLAYER_A); return GetPossibleMoves(previousMaze).Any(coordinate => coordinate.X.Equals(currentPosition.X) && coordinate.Y.Equals(currentPosition.Y)); }
public static bool IsOutOfPills(Maze maze) { var flatFormatMaze = maze.ToFlatFormatString(); return !(flatFormatMaze.Contains(Properties.Settings.Default.SymbolPill) || flatFormatMaze.Contains(Properties.Settings.Default.SymbolPowerPill)); }
private static bool IsMoveMadeAndDiedFromPoisonPill(Maze previousMaze, Point currentPosition) { return previousMaze.GetSymbol(currentPosition.X, currentPosition.Y) == Symbols.SYMBOL_POISON_PILL; }
private void CreateIterationStateFile(String folderPath) { var replayFile = new StreamWriter(folderPath + "\\" + Properties.Settings.Default.SettingReplayFolder + "\\iteration" + _iteration + Properties.Settings.Default.SettingStateFileExtension); var mazeForFile = new Maze(_maze); if (_secondMazePlayer == _currentPlayer.GetSymbol()) mazeForFile.SwapPlayerSymbols(); replayFile.Write(mazeForFile.ToFlatFormatString()); replayFile.Close(); }
private static bool IsMoveMadeAndScoredPoint(Maze previousMaze, Point currentPosition) { return previousMaze.GetSymbol(currentPosition.X, currentPosition.Y) == Symbols.SYMBOL_PILL; }
private Player DeterminIfWinner(Enums.GameOutcome gameOutcome, Maze mazeFromPlayer, Player winner) { mazeFromPlayer.SwapPlayerSymbols(); _maze = mazeFromPlayer; if (gameOutcome != Enums.GameOutcome.ProceedToNextRound) { if (gameOutcome == Enums.GameOutcome.NoScoringMaxed) { winner = _playerPool.GetNextPlayer(); } else { winner = GameJudge.DetermineWinner(_playerPool); } } return winner; }
private static bool IsMoveMadeAndScoredPoint(Maze previousMaze, Point currentPosition) { return previousMaze.GetSymbol(currentPosition.X, currentPosition.Y).Equals(Properties.Settings.Default.SymbolPill); }
private Enums.GameOutcome GetGameOutcome(Maze mazeFromPlayer, StreamWriter logFile, Enums.GameOutcome gameOutcome, Enums.TurnOutcome turnOutcome) { logFile.WriteLine("[GAME] : Player " + _currentPlayer.GetPlayerName() + " has " + _currentPlayer.GetScore() + " points"); logFile.WriteLine("[TURN] : Moved to " + _currentPlayer.GetCurrentPosition().X + ", " + _currentPlayer.GetCurrentPosition().Y); gameOutcome = _gameMarshaller.ProcessGame(mazeFromPlayer, turnOutcome); logFile.WriteLine("[TURN] : " + _gameMarshaller.GetTurnsWithoutPointsInfo() + " turns without points"); logFile.WriteLine("[GAME] : " + gameOutcome); return gameOutcome; }
private Enums.MazeValidationOutcome GetMazeValidationOutcome(StreamWriter logFile, Maze mazeFromPlayer) { logFile.WriteLine("[GAME] : Received maze from player " + _currentPlayer.GetPlayerName()); var mazeValidationOutcome = (MazeValidator.ValidateMaze(mazeFromPlayer, _maze, logFile)); logFile.WriteLine("[MAZE] : " + mazeValidationOutcome); return mazeValidationOutcome; }
private static bool IsMazeValid(Maze currentMaze, Maze previousMaze) { return GetNumberOfDifferences(currentMaze, previousMaze) == _EXACT_NUMBER_OF_DIFFERENCES_FOR_LEGAL_MOVE; }