-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathChessBot.m
51 lines (40 loc) · 1.41 KB
/
ChessBot.m
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
classdef ChessBot < handle
properties
Board % ChessBoard
Tensile % double [0-1]
Turns % int16 [0-n]
IsVerbose % boolean
end
methods
function obj = ChessBot(Board, Tensile, IsVerbose)
obj.Board = Board;
obj.Tensile = Tensile;
obj.Turns = 1;
switch nargin
case 1
obj.Tensile = 0.5;
obj.IsVerbose = false;
case 2
obj.Tensile = Tensile;
obj.IsVerbose = false;
case 3
obj.Tensile = Tensile;
obj.IsVerbose = IsVerbose;
end
end
% Do not call this if the bot is checkmated.
function [oldpos, newpos] = nextmove(obj, enigspace)
cb = obj.Board;
% Get all resolving moves
rmoves = cb.rpmoves(2);
% Sort moves by mscore (h -> l)
[~, minds] = insort(cellfun(@(m) cb.mscore(unwrap(m(1), 1), unwrap(m(2), 1), enigspace), rmoves));
% Get entropic index (and item)
erange = clamp(ceil(obj.Tensile * 3 * (1 - cb.bscore / 25)), 1, 3);
eimove = unwrap(rmoves(minds(randi(erange))), 1);
[oldpos, newpos] = eimove{:};
% Increment turn count
obj.Turns = obj.Turns + 1;
end
end
end