-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathProgram.cs
More file actions
91 lines (88 loc) · 3.44 KB
/
Program.cs
File metadata and controls
91 lines (88 loc) · 3.44 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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ChessNN
{
class Program
{
static Player player1 = new Player(true);
static Player player2 = new Player(false);
public static Board ActiveBoard = new Board(player1, player2, new Piece[8, 8], true);
static void Main(string[] args)
{
ActiveBoard.Pieces = Board.initBoard(ActiveBoard);
Board.PrintBoard(ActiveBoard);
activeUI();
}
public static void activeUI()
{
Console.WriteLine("Command?");
string command = Console.ReadLine();
try
{
if (command[0] == 'm')
{
bool x = int.TryParse(command[1].ToString(), out int result);
bool y = int.TryParse(command[2].ToString(), out int result2);
bool z = int.TryParse(command[3].ToString(), out int result3);
bool q = int.TryParse(command[4].ToString(), out int result4);
if (x && y && z && q)
{
ActiveBoard = (ActiveBoard.Pieces[result, result2]).Move(ActiveBoard, result3, result4);
}
}
if (command.ToLower() == "learn")
{
NeuralNet.Play(ActiveBoard);
}
if (command[0] == 'p' || command[0] == 'P')
{
if (ActiveBoard.WTurn)
{
NeuralNet NN = new NeuralNet(player1, 3, 10);
Data.ReadNs(NN);
ActiveBoard = NN.Move(ActiveBoard, NN.Player.IsW);
}
else
{
NeuralNet NN = new NeuralNet(player2, 3, 10);
Data.ReadNs(NN);
ActiveBoard = NN.Move(ActiveBoard, NN.Player.IsW);
}
}
if (command == "initialize")
{
NeuralNet NN = new NeuralNet(player2, 3, 10);
NN.initNN();
Data.WriteNs(NN);
}
if (command == "load")
{
NeuralNet NN = new NeuralNet(player2, 3, 10);
Data.ReadNs(NN);
Data.WriteNs(NN);
}
//'s' to stop learning
if (command.Length >= 2 && command[0] == 'p' && command[1] == 'm')
{
bool x = int.TryParse(command[2].ToString(), out int result);
bool y = int.TryParse(command[3].ToString(), out int result2);
bool z = int.TryParse(command[4].ToString(), out int result3);
bool q = int.TryParse(command[5].ToString(), out int result4);
if (x && y && z && q)
{
ActiveBoard.Pieces[result, result2].Move(ActiveBoard, result3, result4);
}
}
}
catch (Exception ex) { Console.WriteLine("Failure"); Console.WriteLine(ex); }
finally
{
Board.PrintBoard(ActiveBoard);
activeUI();
}
}
}
}