forked from rliffredo/battleships
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
63 lines (58 loc) · 1.79 KB
/
Copy pathProgram.cs
File metadata and controls
63 lines (58 loc) · 1.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
using System;
using System.Net;
namespace Battleships
{
class Program
{
static void Main()
{
// ignore HTTPS certificate errors
ServicePointManager.ServerCertificateValidationCallback =
(sender, cert, chain, policy) => true;
try
{
var gameApi = new RestApi();
var i = 0;
while (i < 10)
{
Console.WriteLine("Game {0}:", i + 1);
PlayGame(gameApi);
++i;
}
Console.WriteLine("current score: " + gameApi.GetCurrentScore());
}
catch (Exception ex)
{
Console.WriteLine(ex);
}
}
static string GetShotResult(ShotResult result)
{
switch (result)
{
case ShotResult.Miss:
return ".";
case ShotResult.Hit:
return "x";
case ShotResult.HitAndSunk:
return "X";
}
return " ";
}
private static void PlayGame(RestApi gameApi)
{
Decision.IDecision d = new Decision.DecisionOld();
var gameId = gameApi.CreateNewGame();
GameState state;
var shoots = 0;
do
{
shoots++;
var coords = d.CellToAttack();
state = gameApi.Shoot(gameId, coords.Item1, coords.Item2);
d.UpdateWithFeedback(coords.Item1, coords.Item2, state.LastShot);
} while (!state.IsFinished);
Console.WriteLine("Total shoots: " + shoots);
}
}
}