makefile
[arrocco.git] / main.py
blob7bbeb8ce1715e1ba559ca6644bce186fb11fd3a9
1 # main.py
3 """
4 This file is part of Arrocco, which is Copyright 2007 Thomas Plick
5 (tomplick 'at' gmail.com).
7 Arrocco is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 Arrocco is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>.
19 """
21 from position import *
22 import thread, time
24 import sys, os
26 fen = (sys.argv + ["-"])[1]
29 def strangeKey((x, y)):
30 if x == 'pv': return ('zzzzzzz', y)
31 else: return (x, y)
34 def f():
35 if fen == '-': pos = ipos
36 else: pos = position(fen)
38 result = {'pv' : []}
39 for depth in range(0, 1000):
40 print "\n"
41 a = time.time()
42 result = alphaBetaWithOldPV(pos, depth, oldVariation = result['pv'])
43 b = time.time()
44 for (k, v) in sorted(result.items(), key = strangeKey):
45 if k != 'pv':
46 if k == 'value' and pos.turn == 1:
47 v *= -1
48 print "%s: %s" % (k, v)
49 print "Variation: %s" % algebraicForPV(result['pv'])
50 print "Took %s seconds" % (int(b-a)+1)
52 global running
53 running = False
54 sys.exit(0)
57 def alphaBetaWithOldPV2(pos, depth, oldVariation):
58 arr = (Position * len(oldVariation))()
59 arr[:] = oldVariation
60 children = (Position * (depth * 512))()
61 counter = int64(0)
63 value = lib.alphaBetaWithOldPV(ctypes.byref(pos), children,
64 depth, -99999, 99999, ctypes.byref(counter), arr, len(oldVariation))
66 L = []
67 node = pos
68 for i in range(depth + 1):
69 L.append(node)
70 try:
71 node = node.children()[self.branch[i]]
72 except:
73 pass
75 return dict(depth = depth, value = value, pv = L, nodeCount = counter.value)
77 running = True
78 if __name__ == '__main__':
79 thread.start_new_thread(f, ())
80 while running:
81 time.sleep(1000)