-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathNN_AI.hpp
68 lines (50 loc) · 2.18 KB
/
NN_AI.hpp
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
#ifndef NNAI_HPP
#define NNAI_HPP
/**
* @file /home/ryan/uml/robotics/checkers/NNAI.hpp
* @author Ryan Domigan <ryan_domigan@[email protected]>
* Created on Apr 07, 2014
*
* A neural network based AI for playing checkers
*/
#include <tuple>
#include <genetic.hpp> /* from nnet */
#include <NNet.hpp>
#include "./Board.hpp"
class NNAI {
public:
typedef NNet< Nums<4, 1> > Net3x3_odd;
typedef NNet< Nums<5, 1> > Net3x3_even;
typedef NNet< Nums<32, 10, 8, 8, 1> > BoardNet;
typedef NNet< Nums<2, 1> > Output; /* combine the peice count part with the BoardNet part */
BoardNet position_net;
Output output_net;
/* typedef MetaNNet< MetaLayer<Net3x3_odd, Net3x3_even, Net3x3_odd, Net3x3_even, Net3x3_odd, Net3x3_even */
/* , Net3x3_even, Net3x3_odd, Net3x3_even, Net3x3_odd, Net3x3_even, Net3x3_odd */
/* , Net3x3_odd, Net3x3_even, Net3x3_odd, Net3x3_even, Net3x3_odd, Net3x3_even */
/* , Net3x3_even, Net3x3_odd, Net3x3_even, Net3x3_odd, Net3x3_even, Net3x3_odd */
/* , Net3x3_odd, Net3x3_even, Net3x3_odd, Net3x3_even, Net3x3_odd, Net3x3_even */
/* , Net3x3_even, Net3x3_odd, Net3x3_even, Net3x3_odd, Net3x3_even, Net3x3_odd */
/* , Net5x5_odd, Net5x5_even, Net5x5_odd, Net5x5_even */
/* , Net5x5_even, Net5x5_odd, Net5x5_even, Net5x5_odd */
/* , Net5x5_odd, Net5x5_even, Net5x5_odd, Net5x5_even */
/* , Net5x5_even, Net5x5_odd, Net5x5_even, Net5x5_odd */
/* , Net8x8> */
/* MetaLayer< Nums<36 + 16 + 1> */
float apply(State color, const Board& board) {
using namespace std;
BoardNet::Feed board_feed;
Output::Feed output_feed;
board.color_ordered(color, board_feed.layer, output_feed.layer[0]);
cout << "Input board: ";
print_array(board_feed.layer) << endl;
cout << "\nCount: " << output_feed.layer[0] << endl;
predict(position_net, board_feed);
output_feed.layer[1] = board_feed.output_layer()[0];
predict(output_net, output_feed);
return output_feed.output_layer()[0];
}
NNAI() : position_net{} , output_net{} {}
NNAI(const BoardNet& b_init, const Output& o_init) : position_net(b_init), output_net(o_init) {}
};
#endif