1 #include "silverfish.h"
7 bool sort_scores(pair<Square*, double> & a, pair<Square*, double> & b)
9 return a.second > b.second;
13 Silver::Silver(const string & colour, int new_max_depth) : Agent(colour), values(), max_depth(new_max_depth), depth(0),
15 values[Piece::PAWN] = 1;
16 values[Piece::BISHOP] = 3;
17 values[Piece::KNIGHT] = 3;
18 values[Piece::ROOK] = 5;
19 values[Piece::QUEEN] = 9;
20 values[Piece::KING] = 100;
21 values[Piece::UNKNOWN] = 1.5;
24 Silver::Silver(const string & colour, const map<Piece::Type, double> & new_values, int new_max_depth)
25 : Agent(colour), values(new_values), max_depth(new_max_depth), depth(0)
27 //TODO: Assert map is valid
30 Move Silver::BestMove(Piece::Colour c)
35 Square & Silver::Select()
39 for (int x = 0; x < BOARD_WIDTH; ++x)
41 for (int y = 0; y < BOARD_HEIGHT; ++y)
43 Square & s = board.SquareAt(x,y);
45 if (s.piece != NULL && s.piece.colour == colour)
48 map<Piece*, double> m = board.SquareAt(x,y).Coverage(colour);
50 for (map<Piece*, double>::iterator i = m.begin(); i != m.end(); ++i)
52 moves[i->first].push_back(pair<Square*, double>
57 for (map<Piece*, vector<pair<Square*, double> > >::iterator i = moves.begin(); i < moves.end()
61 Square & Silver::Move()
63 vector<Square*> moves;
64 board.Get_moves(selected);
67 double ScoreMove(Piece * p, Square & target)
71 if (target.piece == NULL)
74 score = 0.5*(values[target.piece->types[0]] + values[target.piece->types[1]]);
76 if (depth < max_depth)
80 BestMove(Piece::Opposite(p->colour));