-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDebugC.cs
More file actions
102 lines (88 loc) · 3.3 KB
/
DebugC.cs
File metadata and controls
102 lines (88 loc) · 3.3 KB
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
using System;
using System.Collections;
using System.Collections.Generic;
namespace QuickChess
{
public static class DebugC
{
public static Dictionary<int, string> map;
public static void Init()
{
map = new Dictionary<int, string>();
string letters = "abcdefgh";
int n = 0;
for (int i = 1; i < 9; i ++)
{
foreach (char chara in letters)
{
string square = chara.ToString();
square += i.ToString();
map.Add (n, square);
n ++;
}
}
}
public static string IndexToString (int index)
{
return map[index];
}
public static int StringToIndex (string sqr)
{
int square = 0;
string letters = "abcdefgh";
square += (int.Parse(sqr[1].ToString())-1) * 8;
square += letters.IndexOf (sqr[0].ToString());
return square;
}
public static string DebugBinary (UInt64 bit, bool format = false, Board b = null)
{
string binary = Convert.ToString((long)bit, 2);
while (binary.Length < 64)
{
binary = "0" + binary;
}
string result = "";
for (int x = 0; x < 8; x ++) {
for (int y = 7; y >= 0; y --)
{
int ind = x * 8 + y;
string letter = binary[ind].ToString();
if (format && letter == "1")
{
int pieceIndex = 0;
bool isWhite = false;
System.Action<Pieces> getPiece = delegate(Pieces x) {
bool inPieces = (x.bitmap & (1UL << (63-ind))) != 0;
if (inPieces)
{
if (Array.IndexOf (b.white.pieces, x) != -1)
{
pieceIndex = Array.IndexOf (b.white.pieces, x);
isWhite = true;
return;
} if (Array.IndexOf (b.black.pieces, x) != -1)
{
pieceIndex = Array.IndexOf (b.black.pieces, x);
isWhite = false;
return;
}
}
};
Array.ForEach (b.white.pieces, getPiece);
Array.ForEach (b.black.pieces, getPiece);
letter = PieceMap.names[pieceIndex];
if (!isWhite)
{
letter = letter.ToLower();
}
}
if (letter == "0") letter = ".";
result += letter + " ";
}
result += "\n";
}
Console.WriteLine (result);
return result;
}
}
}