Python Question for chess players.

Is it possible to script a chess game n Blender. Computer AI and all.

I bet it is, but i have never tryed so i cant tell you how :expressionless:

it would really be possible for_you if you knew how to do one outside of blender

yeah, it could be done in blender. you may have to make some decisions tho, will it try to determine its next move on one frame or on several?
[and how would you implement that]

Well I know it’s possible to do outside of blender but the python modules can’t calculate the computer’s moves. http://www.alcyone.com/software/chess/ This is the only working example that I could find for doing it.

Kind of off-topic, but do you play chess a lot? I’ve played since 3rd grade, and i got 3rd place at state last year in Colorado, USA.

Pooba

Well not often enough to win prizes or contest but often enough to remember the game.

Ok I explored this about 14 years ago. If you know how to program computer AI/Gameplay. It looks like this module had done most of th work for you in that it verifies legal moves and keeps track of positions. You would have to code the search tree to find out the best move. Then code the blender game modules to make that move on scree. AND NO I am not a good enough programmer/coder to do this.

The best way to do this would be to use an existing chess engine (like gnuchess.)

There is a defined protocol you use for telling the engine where to move, and the engine tells you if it is legal/what the computer player does.

The best way to do this would be to use an existing chess engine (like gnuchess.)

There is a defined protocol you use for telling the engine where to move, and the engine tells you if it is legal/what the computer player does.

But is it possible to use it in Blender’s game engine

Well, if you can get the source code of a chess game, you have the most difficult task.

Well I have the source but I have no clue how to port it. The link is at the top.

Links:
GnuChess
Crafty

The XBoard Protocol

Basically, you run the engine from python with popen2:


input, output = popen2("engine")

output.write(mymove)
computermove = input.read()
updateboard(computermove)

You use the XBoard protocol to write to the chess engine, and you read it’s moves etc back.

I’m sure there are details in there that will complicate things, but that should get you started.

Great advice but I want to get a few things straight: use the external engine for the moves for the computer but how do I get the engine to read the players move so that it can give the best possibilty?

You have to work out the players move from your interface - start with something simple, like having the user input “e4”. Then work out a method of getting “e4” from the mouse clicks.

So you have to read the players move, then pass it to the engine.