-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathChessEngine.cs
More file actions
122 lines (107 loc) · 3.63 KB
/
Copy pathChessEngine.cs
File metadata and controls
122 lines (107 loc) · 3.63 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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
using Autodesk.Revit.DB;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace NEWREVITADDIN
{
struct Position
{
int Column { get; set; }
int Row { get; set; }
}
class ChessEngine
{
public static Process Start()
{
string chessEngineFilePath = @"C:\Users\peter.morton\source\repos\ConsoleApp2\bin\Debug\ConsoleApp2.exe";
Process process = new Process();
process.StartInfo.FileName = chessEngineFilePath;
process.StartInfo.CreateNoWindow = false;
process.StartInfo.RedirectStandardInput = true;
process.StartInfo.UseShellExecute = false;
process.Start();
return process;
// process.StandardInput.WriteLine("uci");
}
public static PieceClass CPUMove(string HumanPlayerMove, Process cheessEngine, List<PieceClass> pieceList)
{
string filename = @"C:\Users\peter.morton\Documents\Chess\NextMove.txt";
string previousCPUMove = System.IO.File.ReadAllLines(filename).Last();
string nextCPUMMove = previousCPUMove;
cheessEngine.StandardInput.WriteLine(HumanPlayerMove);
System.Threading.Thread.Sleep(4050);
while (previousCPUMove == nextCPUMMove)
{
nextCPUMMove = System.IO.File.ReadAllLines(filename).Last();
}
var initialColumn = nextCPUMMove[0];
var endColumn = nextCPUMMove[2];
int initialColumnInt = charToInt(initialColumn);
int endColumnInt = charToInt(endColumn);
int initialRow = charToStr(nextCPUMMove[1]);
int endRow = charToStr(nextCPUMMove[3]);
foreach (PieceClass piece in pieceList)
{
if (piece.Row == initialRow && piece.Col == initialColumnInt)
{
piece.Row = endRow;
piece.Col = endColumnInt;
return piece;
}
}
return null;
}
private static int charToInt(char column)
{
if (column == 'a')
return 1;
else if (column == 'b')
return 2;
else if (column == 'c')
return 3;
else if (column == 'd')
return 4;
else if (column == 'e')
return 5;
else if (column == 'f')
return 6;
else if (column == 'g')
return 7;
else if (column == 'h')
return 8;
else
return 0;
}
private static int charToStr(char column)
{
if (column == '1')
return 1;
else if (column == '2')
return 2;
else if (column == '3')
return 3;
else if (column == '4')
return 4;
else if (column == '5')
return 5;
else if (column == '6')
return 6;
else if (column == '7')
return 7;
else if (column == '8')
return 8;
else
return 0;
}
public static string generateMoveString(int col1, int col2, int row1, int row2)
{
string alphabet = "abcdefgh";
var col1str = alphabet[col1 - 1];
var col2str = alphabet[col2 - 1];
return col1str + row1.ToString() + col2str + row2.ToString();
}
}
}