static void Main(string[] args) { var board = new BattleshipBoard(); //ai.Play(board); Console.ReadLine(); }
static void Main(string[] args) { BattleshipBoard b = new BattleshipBoard(); AI ai = new AI(); b.Fire() ai.Play() }
static void Main(string[] args) { BattleshipBoard board = new BattleshipBoard(); MyBattleshipAi myBattleshipAi = new MyBattleshipAi(); //board.CreateRandomBoard(); myBattleshipAi.Play(board); Console.ReadLine(); }
static void Main(string[] args) { BattleshipBoard board = new BattleshipBoard(); TigerWarShip tigerWarShip = new TigerWarShip(); board.CreateRandomBoard(); tigerWarShip.Play(board); Console.WriteLine(tigerWarShip.GetTeamName()); Console.ReadLine(); }
public Dictionary<string, TeamResults> CheckTopic(string[,] problem, int repeatCount) { Dictionary<string, TeamResults> results = new Dictionary<string, TeamResults>(); for (int i = 0; i < repeatCount; i++) { var dlls = GetBattleshipAis(); foreach (var ai in dlls) { var teamName = "no name"; try { teamName = ai.GetTeamName(); } catch {} if (!results.ContainsKey(teamName)) results[teamName] = new TeamResults() { TeamName = teamName, FireCount = 0 }; DummyDisplay display = new DummyDisplay(); BattleshipBoard board = new BattleshipBoard(display, problem); var start = DateTime.Now; //// var tokenSource = new CancellationTokenSource(); CancellationToken token = tokenSource.Token; int timeOut = 20000; var task = Task.Factory.StartNew(() => ai.Play(board), token); if (!task.Wait(timeOut, token)) { Console.WriteLine("The Task " + teamName + " timed out!"); } // //ai.Play(board); if (display.IsMissionCompleted) { results[teamName].FireCount = results[teamName].FireCount + board.FireCount; } else { results[teamName].FireCount = -1; } var timeTaken = DateTime.Now.Subtract(start).TotalMilliseconds; results[teamName].TimeTaken = timeTaken; } } foreach (var result in results) { result.Value.FireCount = (result.Value.FireCount < 0 ? result.Value.FireCount : result.Value.FireCount / repeatCount); } return results; }
public void Fire_WhenCorrectAll_ThenReturnCompleted() { BattleshipBoard board = new BattleshipBoard(); // Ship 5 length var result = board.Fire(2, 1); Assert.AreEqual(Result.HIT, result); result = board.Fire(2, 2); Assert.AreEqual(Result.HIT, result); result = board.Fire(2, 3); Assert.AreEqual(Result.HIT, result); result = board.Fire(2, 4); Assert.AreEqual(Result.HIT, result); result = board.Fire(2, 5); Assert.AreEqual(Result.HIT, result); // Ship 2 length result = board.Fire(4, 5); Assert.AreEqual(Result.HIT, result); result = board.Fire(5, 5); Assert.AreEqual(Result.HIT, result); // Ship 3 length x 2 result = board.Fire(7, 2); Assert.AreEqual(Result.HIT, result); result = board.Fire(8, 2); Assert.AreEqual(Result.HIT, result); result = board.Fire(9, 2); Assert.AreEqual(Result.HIT, result); result = board.Fire(9, 3); Assert.AreEqual(Result.HIT, result); result = board.Fire(9, 4); Assert.AreEqual(Result.HIT, result); result = board.Fire(9, 5); Assert.AreEqual(Result.HIT, result); // Ship 4 length result = board.Fire(8, 6); Assert.AreEqual(Result.HIT, result); result = board.Fire(8, 7); Assert.AreEqual(Result.HIT, result); result = board.Fire(8, 7); Assert.AreEqual(Result.HIT, result); result = board.Fire(1, 1); Assert.AreEqual(Result.MISS, result); result = board.Fire(8, 8); Assert.AreEqual(Result.HIT, result); result = board.Fire(8, 9); Assert.AreEqual(Result.MISSION_COMPLETED, result); result = board.Fire(8, 9); Assert.AreEqual(Result.MISSION_COMPLETED, result); result = board.Fire(1, 1); Assert.AreEqual(Result.MISSION_COMPLETED, result); Assert.AreEqual(21, board.FireCount); }
static void Main(string[] args) { Console.BackgroundColor = ConsoleColor.Black; Console.Clear(); ConsoleDisplay2Board console1 = new ConsoleDisplay2Board(); BattleshipBoard board1 = new BattleshipBoard(console1); BattleshipBoard board2 = new BattleshipBoard(console1); IBattleshipAi ai1 = new BattleshipAi.BattleshipAi(); IBattleshipAi ai2 = new MyAi2(); console1.Display(ai1, ai2, board1, board2); Console.ReadLine(); }
internal void Display(IBattleshipAi ai1, IBattleshipAi ai2, BattleshipBoard board1, BattleshipBoard board2) { board1Id = board1.GetId(); board2Id = board2.GetId(); boardData[board1Id] = new BoardObject(board1Id, ai1.GetTeamName()); boardData[board2Id] = new BoardObject(board2Id, ai2.GetTeamName()); PrintBoard(); Parallel.Invoke(() => { ai1.Play(board1); }, () => { ai2.Play(board2); }); //Console.WriteLine(); //Console.WriteLine(ai1.GetTeamName() + " WIN!!"); }
public void Fire_RowOverThan10ShouldThrowException() { BattleshipBoard board = new BattleshipBoard(); board.Fire(1, 11); }
public void Fire_RowLowerThan0ShouldThrowException() { BattleshipBoard board = new BattleshipBoard(); board.Fire(1, 0); }
public void Fire_ColumnLowerThan0ShouldThrowException() { BattleshipBoard board = new BattleshipBoard(); board.Fire(0, 1); }
public void Fire_WhenIncorrectColumnAndRow_ThenReturnMISS() { BattleshipBoard board = new BattleshipBoard(); var result = board.Fire(1, 1); Assert.AreEqual(Result.MISS, result); }
public void Fire_WhenCorrectColumnAndRow_ThenReturnHIT() { BattleshipBoard board = new BattleshipBoard(); var result = board.Fire(2, 1); Assert.AreEqual(Result.HIT, result); }
public async Task<string> DoPlay(int problemNo) { if (display.IsPlaying()) { return "Playing game."; } var dlls = GetBattleshipAis(); IBattleshipAi ai1 = dlls[0]; IBattleshipAi ai2 = dlls[1]; display = new WebDisplay(); //display.Delay = 200; string[,] problem = getProblem(problemNo); BattleshipBoard board1 = new BattleshipBoard(display, problem); BattleshipBoard board2 = new BattleshipBoard(display, problem); display.setBoardId1(board1.GetId(), ai1.GetTeamName()); display.setBoardId2(board2.GetId(), ai2.GetTeamName()); Task.Factory.StartNew(() => { Parallel.Invoke(() => ai1.Play(board1), () => ai2.Play(board2)); }); return "Starting game."; }