-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRandomGamePlayer.cs
69 lines (59 loc) · 1.8 KB
/
RandomGamePlayer.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
/*
* RandomGamePlayer.cs --
*
* Copyright (c) 2007-2024 by Joe Mistachkin. All rights reserved.
*
* See the file "license.terms" for information on usage and redistribution of
* this file, and for a DISCLAIMER OF ALL WARRANTIES.
*
* RCS: @(#) $Id: $
*/
using System;
namespace TicTacToe
{
internal class RandomGamePlayer : IGamePlayer
{
#region Private Data
//
// NOTE: This is the random number generator used to pick
// an initial search location for computer selected
// moves.
//
private Random random = new Random(Environment.TickCount);
#endregion
///////////////////////////////////////////////////////////////////////
#region IGamePlayer Members
public virtual bool GetRowAndColumn(
IGameBoard gameBoard, /* in */
MarkType turn, /* in */
ref int row, /* out */
ref int column /* out */
)
{
if (gameBoard == null)
return false;
int rows = gameBoard.Rows;
int columns = gameBoard.Columns;
while (true)
{
if (gameBoard.IsFull(true))
break;
row = random.Next(0, rows - 1);
for (; row < rows; row++)
{
column = random.Next(0, columns - 1);
for (; column < columns; column++)
{
if (gameBoard.GetMark(
row, column) == MarkType.None)
{
return true;
}
}
}
}
return false;
}
#endregion
}
}