Example #1
0
	def search(self, time_budget):
		"""
		Compute resistance for all moves in current state.
		"""
		toplay = white if self.state.toplay == self.state.PLAYERS["white"] else black
		raw_scores = score(stateToInput(self.state), toplay)
		score_padding = (boardsize - self.state.size)/2
		self.scores = raw_scores[score_padding:self.state.size+score_padding,score_padding:self.state.size+score_padding]
Example #2
0
import numpy as np
from resistance import score
from preprocess import *

positions = preprocess("data/raw_games.dat")
print "scoring positions..."
scores = np.empty((positions.shape[0],boardsize,boardsize))
num_positions = positions.shape[0]
output_interval = num_positions/100
for i in range(num_positions):
	if(i%output_interval == 0):
		print "completion: ",i/output_interval
	try:
		scores[i]=score(positions[i], 0)
	#if for some reason an uncaught singularity occurs just skip this position
	except np.linalg.linalg.LinAlgError:
		print "singular position at ",str(i),": ", state_string(positions[i])
		i-=1

print "saving to file..."
savefile = open("data/scoredPositionsFull.npz", 'w')
np.savez(savefile, positions=positions, scores=scores)
Example #3
0
import sys
sys.path.append("..")
from inputFormat import state_string, new_game
from resistance import score
from preprocess import preprocess
import numpy as np
import time
"""
Calculate resistance over 10 games and time how long it takes.
"""


pos = preprocess("../data/raw_games_small.dat", trim_final = False)

np.set_printoptions(suppress=True, precision=4, linewidth=150)

start = time.time()
for i in range(len(pos)):
	s = score(pos[i],0)
	if(np.min(np.select([s>-1],[s]))<0 and np.max(s)>0):
		print s
		print state_string(pos[i])
	#print score(pos[i], 0)
print "Computed ", len(pos), "positions in ", time.time() - start, "s"

print state_string(pos[60])
print score(pos[60], 0)