-
Notifications
You must be signed in to change notification settings - Fork 0
/
HumanPlayer.cs
38 lines (33 loc) · 1.08 KB
/
HumanPlayer.cs
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
using System;
using System.Linq;
namespace ColoringGame
{
public class HumanPlayer : Player
{
public HumanPlayer(PlayerNumber playerNumber)
: base(playerNumber)
{ }
public override int SelectField(BoardField[] currentFields)
{
var availableFields = currentFields
.Select((v, i) => new { Value = v, Index = i })
.Where(x => x.Value == BoardField.Empty)
.ToArray();
Console.Write($"Available fields for player {PlayerNumber}: ");
for (var i = 0; i < availableFields.Length; ++i)
{
Console.Write($"{availableFields[i].Index + 1} ");
}
Console.WriteLine();
while (true)
{
Console.Write($"Please write available field number: ");
var read = Console.ReadLine();
if (int.TryParse(read, out int v) && availableFields.Any(f => f.Index == v - 1))
{
return v - 1;
}
}
}
}
}