-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGameWinnerLogic.cs
77 lines (67 loc) · 2.06 KB
/
GameWinnerLogic.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
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace TicTacToe
{
public class GameWinnerLogic
{
public bool GameOver(Board board)
{
for (int row = 0; row < board.Rows; row++)
{
if (board.GetRowSymbol(row) != SymbolOnBoard.Empty)
{
return true;
}
}
for (int column = 0; column < board.Columns; column++)
{
if (board.GetColumnSymbol(column) != SymbolOnBoard.Empty)
{
return true;
}
}
if (board.GetDiagonalFromTopLeftSymbol() != SymbolOnBoard.Empty)
{
return true;
}
if (board.GetDiagonalFromBottomLeftSymbol() != SymbolOnBoard.Empty)
{
return true;
}
return board.IsFull();
}
public SymbolOnBoard GetWinner(Board board)
{
for (int row = 0; row < board.Rows; row++)
{
var winner = board.GetRowSymbol(row);
if (winner != SymbolOnBoard.Empty)
{
return winner;
}
}
for (int column = 0; column < board.Columns; column++)
{
var winner = board.GetColumnSymbol(column);
if (winner != SymbolOnBoard.Empty)
{
return winner;
}
}
var diagonalFromTopWinner = board.GetDiagonalFromTopLeftSymbol();
if (diagonalFromTopWinner != SymbolOnBoard.Empty)
{
return diagonalFromTopWinner;
}
var diagonalFromBottomWinner = board.GetDiagonalFromBottomLeftSymbol();
if (diagonalFromBottomWinner != SymbolOnBoard.Empty)
{
return diagonalFromBottomWinner;
}
return SymbolOnBoard.Empty;
}
}
}