chess

Knight's Tour in Python - Getting Path from Predecessors

谁都会走 提交于 2021-02-11 18:23:47
问题 I'm trying to adapt a Depth-First Search algorithm in Python to solve the Knight's Tour puzzle. I think I've nearly succeeded, by producing a dictionary of predecessors for all the visited squares. However, I'm stuck on how to find the autual path for the Knight. Currently, using the current return value from tour() in path() gives a disappointing path of [(0, 0), (2, 1)] . I think the crux of the issue is determining at what point inside tour() all squares are visited and at that point

Stockfish and Python

这一生的挚爱 提交于 2021-02-07 20:24:31
问题 I'm trying to write a script using python to feed chess positions into stockfish and get evaluations. My question is based on this, How to Communicate with a Chess engine in Python? The issue is with subprocess.pipe. import subprocess, time import os os.chdir('C:\Users\Michael\Downloads\stockfish-6-win\stockfish-6-win\Windows' engine = subprocess.Popen('stockfish', universal_newlines=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE) def put(command): print('\nyou:\n\t'+command) engine

C# Drawing Chess Board

家住魔仙堡 提交于 2021-02-04 16:08:42
问题 I'm trying to draw a 8x8 chess board using C#. Here's my first attempt to draw it. It won't draw the board and I haven't found what I'm missing. public void Form1_Load(object sender, EventArgs e) { Bitmap bm = new Bitmap(8 * 100, 8 * 100); Graphics g = Graphics.FromImage(bm); Color color1, color2; for (int i = 0; i < 8; i++) { if (i % 2 == 0) { color1 = Color.Black; color2 = Color.White; } else { color1 = Color.White; color2 = Color.Black; } SolidBrush blackBrush = new SolidBrush(color1);

C# Drawing Chess Board

你说的曾经没有我的故事 提交于 2021-02-04 16:08:00
问题 I'm trying to draw a 8x8 chess board using C#. Here's my first attempt to draw it. It won't draw the board and I haven't found what I'm missing. public void Form1_Load(object sender, EventArgs e) { Bitmap bm = new Bitmap(8 * 100, 8 * 100); Graphics g = Graphics.FromImage(bm); Color color1, color2; for (int i = 0; i < 8; i++) { if (i % 2 == 0) { color1 = Color.Black; color2 = Color.White; } else { color1 = Color.White; color2 = Color.Black; } SolidBrush blackBrush = new SolidBrush(color1);

Finding correct second image, by smaller representation of first

烂漫一生 提交于 2021-01-29 14:53:46
问题 Let's take a look at this chessboard (https://prnt.sc/r8vjth) As you can see, there are two greenish squares (g8 and f6), which indicate the enemy's move. Square g8 is empty and is pretty easy to find by locateOnScreen function. Problems begin when I am trying to find f6 because it returns again the g8's position. For example, in screenshot's position, it finds the g8. First part is correct, and it comes from the h parameter in the code below. But the second g8 is coming from this function,

Generate Chess Board Diagram from an array of positions in Python?

假如想象 提交于 2021-01-29 10:47:32
问题 I have an array which corresponds to the positions of pieces on a chessboard, like so: ['em', 'bn', 'em', 'wr', 'em', 'wp', 'em', 'em'] ['br', 'em', 'bp', 'em', 'em', 'bn', 'wn', 'em'] ['em', 'em', 'bp', 'bp', 'bp', 'em', 'wp', 'bp'] ['bp', 'bp', 'em', 'bp', 'wn', 'em', 'wp', 'em'] .... The 'b' and 'w' signify black and white. n: knight r: rook p: pawn b: bishop k: king q: queen I want to know if there exists some utility which can take this array or something similar and generate a picture

Understanding “o^(o-2r)” formula for generating sliding piece moves using unsigned bitboards?

狂风中的少年 提交于 2021-01-28 20:14:32
问题 What I Am Trying To Do I am trying to perform some bitwise operations to create a chess engine. To make this engine, I need to be able to generate moves for pieces, like rooks. There is a handy formula for creating a bitboard of squares available for the rook to move to: bitboardOfOccupiedSquares ^ (bitboardOfOccupiedSquares - 2 * bitboardOfPieceToMove) . Consider the following chess board position: I am trying to generate all of the squares that the rook on h1 can move to. So this should be

Tying a unique game id to a user in a Flask app to handle multiple requests to the server

三世轮回 提交于 2020-07-23 07:41:26
问题 I built a chess app with Python and used Flask to create a site for users to play on. I used Heroku to deploy the app (http://pythonchessapp.herokuapp.com/). I am new to web development and was wondering how I can handle multiple users (on separate laptops or tabs) going on the site to play the app? Something like having a unique game id per user to serve a different game to different requests. Below is some of my code for routes and initializing games. I basically initialize a Board object

Tying a unique game id to a user in a Flask app to handle multiple requests to the server

折月煮酒 提交于 2020-07-23 07:39:06
问题 I built a chess app with Python and used Flask to create a site for users to play on. I used Heroku to deploy the app (http://pythonchessapp.herokuapp.com/). I am new to web development and was wondering how I can handle multiple users (on separate laptops or tabs) going on the site to play the app? Something like having a unique game id per user to serve a different game to different requests. Below is some of my code for routes and initializing games. I basically initialize a Board object

How to do for loop with all possible combinations of pairs (+- 1, +- 2)

假如想象 提交于 2020-05-24 03:31:47
问题 I'm drawing possible paths of a knight in chess and one case looks like this: if (boundsOK(x + 1, y + 2)) { temp = boardArray[x + 1][y + 2]; if (isLegalMove(x, y, x + 1, y + 2) != MoveType.NONE) { moves.add(x); moves.add(y); moves.add(x + 1); moves.add(y + 2); move(x + 1, y + 2, x, y); } boardArray[x + 1][y + 2] = temp; } Now instead of 1 and 2, I want to construct a loop which would try out combinations: 1 2 -1 2 1 -2 -1 -2 2 1 -2 1 2 -1 -2 -1 But I don't know how to do it without unnecesary