forked from paviad/GoSharp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
BoardComparer.cs
43 lines (41 loc) · 1.35 KB
/
BoardComparer.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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Go
{
/// <summary>
/// This class implements IEqualityComparer<Board> that compares boards by
/// their content. The purpose of this class is to enable the super-ko rule.
/// </summary>
public class SuperKoComparer : IEqualityComparer<Board>
{
/// <summary>
/// Returns true if two Board objects have the same content.
/// </summary>
/// <param name="x">The first Board object.</param>
/// <param name="y">The second Board object.</param>
/// <returns>True if the Boards have the same content.</returns>
public bool Equals(Board x, Board y)
{
if (x.SizeX != y.SizeX || x.SizeY != y.SizeY) return false;
for (int i = 0; i < x.SizeX; i++)
{
for (int j = 0; j < x.SizeY; j++)
{
if (x[i, j] != y[i, j]) return false;
}
}
return true;
}
/// <summary>
/// Returns a hash code based on the content of the board.
/// </summary>
/// <param name="obj">The Board object.</param>
/// <returns></returns>
public int GetHashCode(Board obj)
{
return obj.GetContentHashCode();
}
}
}