-
Notifications
You must be signed in to change notification settings - Fork 0
/
Board.cs
35 lines (34 loc) · 975 Bytes
/
Board.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
using System;
using System.Collections.Generic;
using System.Text;
using static TicTacToe.Program;
namespace TicTacToe
{
public class Board
{
private State[,] state;
public State NextTurn { get; private set; }
public Board()
{
state = new State[3, 3];
NextTurn = State.X;
}
public State GetState(Position position)
{
return state[position.Row, position.Column];
}
public bool SetState(Position position, State newState)
{
if (newState != NextTurn) return false;
if (state[position.Row, position.Column] != State.Undecided) return false;
state[position.Row, position.Column] = newState;
SwitchNextTurn();
return true;
}
private void SwitchNextTurn()
{
if (NextTurn == State.X) NextTurn = State.O;
else NextTurn = State.X;
}
}
}