def getVal(FEN): syzygy = chess.syzygy.Tablebases() num = 0 num += syzygy.open_directory(os.path.join(os.path.dirname(__file__), "four-men")) board = chess.Board(FEN) expectVal = syzygy.probe_wdl(board) return expectVal
def userInput(): print "" print "This is an endgame solver designed to solve 3,4 and 5 piece chess" print "Currently it can solve the following board combinations: " #fill print "Please enter the board in algebraic notation, enter . when you are done" print "Uppercase letters define white's pieces, while lowecase define black's pieces" print "If there are 2 pieces on the same row, please enter them in ascending order (ka1 before Pa3)" print "" pieces = [] while True: newPiece = raw_input('Enter new piece: ') if newPiece == ".": break else: pieces.append(newPiece) FEN = processInput(pieces) turn = raw_input('Whose move is it (b or w): ') board = chess.Board(FEN + " " + turn + " - - 0 1") syzygy = chess.syzygy.Tablebases() num = 0 num += syzygy.open_directory( os.path.join(os.path.dirname(__file__), "four-men")) output = predictOutput(board, syzygy, len(pieces)) actualOutput = output[0] predictedOutput = output[1] if actualOutput != -100: if actualOutput == -1: print "" print "The actual value according to databases is: DRAW" else: print "" print "The actual value according to databases is: WIN" if actualOutput == -1: print "The predicted output according our algorithm is: DRAW" else: print "The predicted output according our algorithm is: WIN" print ""
def userInput(): print "" print "This is an endgame solver designed to solve 3,4 and 5 piece chess" print "Currently it can solve the following board combinations: " #fill print "Please enter the board in algebraic notation, enter . when you are done" print "Uppercase letters define white's pieces, while lowecase define black's pieces" print "If there are 2 pieces on the same row, please enter them in ascending order (ka1 before Pa3)" print "" pieces = [] while True: newPiece = raw_input('Enter new piece: ') if newPiece == ".": break else: pieces.append(newPiece) FEN = processInput(pieces) turn = raw_input('Whose move is it (b or w): ') board = chess.Board(FEN + " " + turn + " - - 0 1") syzygy = chess.syzygy.Tablebases() num = 0 num += syzygy.open_directory(os.path.join(os.path.dirname(__file__), "four-men")) output = predictOutput(board, syzygy, len(pieces)) actualOutput = output[0] predictedOutput = output[1] if actualOutput != -100: if actualOutput == -1: print "" print "The actual value according to databases is: DRAW" else: print "" print "The actual value according to databases is: WIN" if actualOutput == -1: print "The predicted output according our algorithm is: DRAW" else: print "The predicted output according our algorithm is: WIN" print ""
import functools import os.path import warnings import json FEN_TEST = "8/8/2k5/8/4R3/8/8/4K3 w - - 0 1" DEFAULT_FEN = "4k3/8/8/8/8/8/8/4K3 w - - 0 1" #app = Flask(__name__) syzygy = chess.syzygy.Tablebases() num = 0 num += syzygy.open_directory(os.path.join(os.path.dirname(__file__), "four-men")) num += syzygy.open_directory(os.path.join(os.path.dirname(__file__), "five-men")) num += syzygy.open_directory(os.path.join(os.path.dirname(__file__), "six-men", "wdl"), load_dtz=False) num += syzygy.open_directory(os.path.join(os.path.dirname(__file__), "six-men", "dtz"), load_wdl=False) #app.logger.info("Loaded %d tablebase files.", num) #gaviota = chess.gaviota.open_tablebases(os.path.join(os.path.dirname(__file__), "gaviota")) def swap_colors(fen): parts = fen.split() return parts[0].swapcase() + " " + parts[1] + " - - 0 1" def mirror_vertical(fen): parts = fen.split()
import chess.syzygy import chess.gaviota import functools import os.path import warnings import json FEN_TEST = "8/8/2k5/8/4R3/8/8/4K3 w - - 0 1" DEFAULT_FEN = "4k3/8/8/8/8/8/8/4K3 w - - 0 1" app = Flask(__name__) syzygy = chess.syzygy.Tablebases() num = 0 num += syzygy.open_directory( os.path.join(os.path.dirname(__file__), "four-men")) num += syzygy.open_directory( os.path.join(os.path.dirname(__file__), "five-men")) num += syzygy.open_directory(os.path.join(os.path.dirname(__file__), "six-men", "wdl"), load_dtz=False) num += syzygy.open_directory(os.path.join(os.path.dirname(__file__), "six-men", "dtz"), load_wdl=False) app.logger.info("Loaded %d tablebase files.", num) gaviota = chess.gaviota.open_tablebases( os.path.join(os.path.dirname(__file__), "gaviota")) def swap_colors(fen):
import functools import os.path import warnings import json import collections from collections import Counter numPieces = raw_input('Number of pieces: ') inp = raw_input('train or both (both = train and test): ') syzygy = chess.syzygy.Tablebases() num = 0 num += syzygy.open_directory(os.path.join(os.path.dirname(__file__), "four-men")) if int(numPieces) == 3: #print "here" data3 = readExamples('data3.txt') testExamples = data3 trainExamples = data3 if inp == "train": print three.train(trainExamples, trainExamples, three.extractFeatures, "w", syzygy) elif inp == "both": weights = three.train(trainExamples, trainExamples, three.extractFeatures, "w", syzygy) print weights three.test(testExamples, "w", weights, syzygy)
def userInput(): print "" print "This is an endgame solver designed to solve 3,4 and 5 piece chess" print "Currently it can solve the following board combinations: KPvp and KPvskp" print "Please enter the board in algebraic notation, enter a . when you are done" print "Uppercase letters define white's pieces, while lowecase define black's pieces" print "Example entry: Ka3, kb7, Pb4, pc3, ." print "NOTE: 3 piece only accepts the pawn being white so it must include K,P and k to work" print "4 piece accepts a white and a black pawn so it must include K,P,k and p to work" print "" pieces = [] while True: newPiece = raw_input('Enter new piece: ') if newPiece == ".": break else: pieces.append(newPiece) FEN = processInput(pieces) turn = raw_input('Whose move is it (w or b): ') board = chess.Board(FEN + " " + turn + " - - 0 1") if turn == "w": mirror = helper.mirror_image(FEN + " " + "b" + " - - 0 1") else: mirror = helper.mirror_image(FEN + " " + "w" + " - - 0 1") mirrorBoard = chess.Board(mirror) syzygy = chess.syzygy.Tablebases() num = 0 num += syzygy.open_directory(os.path.join(os.path.dirname(__file__), "four-men")) actualOutput = 0 predictedOutput = 0 if len(pieces) == 3: output = predictOutput(board, syzygy, len(pieces)) actualOutput = output[0] predictedOutput = output[1] elif len(pieces) == 4: print "Real Board:" output1 = predictOutput(board, syzygy, len(pieces)) print"" print "Mirrored Board:" output2 = predictOutput(mirrorBoard, syzygy, len(pieces)) actualOutput = output1[0] if (output1[1] == 1 or output2[1] == 1): predictedOutput = 1 else: predictedOutput = -1 if actualOutput != -100: if actualOutput == -1: print "" print "The actual value according to databases is: DRAW" else: print "" print "The actual value according to databases is: WIN" if predictedOutput == -1: print "The predicted output according our algorithm is: DRAW" else: print "The predicted output according our algorithm is: WIN" print ""