Jump to content


Photo
* * * * * 1 votes

Basic Chess Engine


  • Please log in to reply
36 replies to this topic

#1 Jakim

Jakim

    GMC Member

  • GMC Member
  • 28 posts
  • Version:GM8.1

Posted 13 June 2011 - 08:36 PM

  • Title: Basic Chess Engine
  • Description: Chess engine respecting official rules of this game.
  • GM Version: 8.1, 8.0
  • Registered: works with Lite
  • File Type: .gm81, .gmk, .exe
  • File Size: GM81: 52 KB, RAR (EXE): 1.57 MB
  • File Link: EXE+GM81+GMK+GMRES+GML, GM81, GMK , GML, GMRES
In case of downloading only source, you have to download sprite pack:
images

Additional Info

Hi. I don't know it has appeared or no, but I'm proud to present chess engine respecting every rule of this game. If you'll find bugs, let me know. Screen:

Screens:

v1.20:
Posted Image

v1.00:
Posted Image

Warning: script for testing every available move is slow but it's available to turn off.

Edited by Jakim, 31 July 2011 - 04:21 AM.

  • 2

#2 Zesterer

Zesterer

    Professor of Articul

  • GMC Member
  • 1043 posts
  • Version:GM8

Posted 01 July 2011 - 09:01 PM

Wow. I tried building a draughts game about a year ago. It was a dismal fail.

Have even included En passant? If not, include this. Also, castling, if not done already.

(sorry, cannot open file)
  • 0

#3 hawk14

hawk14

    GMC Member

  • GMC Member
  • 745 posts

Posted 02 July 2011 - 12:17 AM

Does it include an AI aswell? I recently created my own chess engine complete with en passant and castling, but no AI. I thought that maybe yours could help.
  • 0

#4 Jakim

Jakim

    GMC Member

  • GMC Member
  • 28 posts
  • Version:GM8.1

Posted 02 July 2011 - 06:43 AM

AI - not yet, but maybe ;).

This engine contains scripts for en passant and castling.

Edited by Jakim, 02 July 2011 - 06:43 AM.

  • 0

#5 Eddygp

Eddygp

    Horizhite Games

  • GMC Member
  • 219 posts
  • Version:GM8

Posted 03 July 2011 - 08:47 AM

Oh, could you adapt it for GM8.0? I tried to open it but I just cannot. :(
  • 0

#6 hawk14

hawk14

    GMC Member

  • GMC Member
  • 745 posts

Posted 03 July 2011 - 09:24 PM

Well that's too bad. Let me know if you figure out a good way to make a decent AI opponent; (or a 'notation' system that keeps track of all your moves; as I'm having trouble with that atm)

Oh and I just thought I should mention that your engine is compatible with Lite users as far as I can tell from using 8.1. (I only have 8.0 registered)

Edited by hawk14, 03 July 2011 - 09:24 PM.

  • 0

#7 Eddygp

Eddygp

    Horizhite Games

  • GMC Member
  • 219 posts
  • Version:GM8

Posted 04 July 2011 - 04:13 PM

Oh, could someone please give me the scripts or codes? or the gmres if are compatible with GM8???
  • 0

#8 Jakim

Jakim

    GMC Member

  • GMC Member
  • 28 posts
  • Version:GM8.1

Posted 05 July 2011 - 10:50 PM

Hi again, glad you liked it.

I have uploaded resources and script file (hope it is available to use for GM 8 users, if no - I will paste here used scripts).
http://jakim.pl/files/chess.gmres
http://jakim.pl/files/chess.gml

obj_main CREATE event:
/* 
|-----------------------------|
| Basic Chess Engine by Jakim |
|-----------------------------|

Including:
- graphic interphace,
- move engine including castling, promotion or en passant capture,
- turn engine: checkmate, stalemate (slow now, trying to improve it),
- nice classical chess sprites ;).
*/

scr_variables_initialize()
scr_create_game()
scr_drawing_options()

obj_main DRAW event:
scr_draw_all()
scr_move_engine()

  • 1

#9 Eddygp

Eddygp

    Horizhite Games

  • GMC Member
  • 219 posts
  • Version:GM8

Posted 07 July 2011 - 08:15 AM

Thanks a lot! The gmres worked!
  • 0

#10 Jakim

Jakim

    GMC Member

  • GMC Member
  • 28 posts
  • Version:GM8.1

Posted 09 July 2011 - 11:59 AM

I'm thinking about doing little, simple AI. I'm open for suggestions :).

And including notation (+FEN/PGN).

Edited by Jakim, 09 July 2011 - 12:05 PM.

  • 0

#11 hawk14

hawk14

    GMC Member

  • GMC Member
  • 745 posts

Posted 11 July 2011 - 02:54 AM

I'm thinking about doing little, simple AI. I'm open for suggestions :).

And including notation (+FEN/PGN).

Is a "little, simple AI" even possible in Chess???
  • 0

#12 stumlehb

stumlehb

    GMC Member

  • GMC Member
  • 200 posts

Posted 11 July 2011 - 03:57 AM

nice. I would like you to make this a battle chess type of engine, so that the pieces have animated movement, attacks, and captures.
  • 0

#13 Jakim

Jakim

    GMC Member

  • GMC Member
  • 28 posts
  • Version:GM8.1

Posted 11 July 2011 - 11:16 AM

Is a "little, simple AI" even possible in Chess???


First of all, this type of AI will respond always the same way (or two, in general - static opponent) - that means playing one way will lead to the same game position. The AI will be not able to learn and correct own mistakes, blunders or inaccuranies. The most part is judging actual position and significant possibilites (with small depth) - computer opponent will play moves gaining better score, of course in own scoring system. Probably the AI won't sacrify own pieces (if it does not lead to obvious force mate). Some engines have such thing as opponent personality (is aggressive/passive etc.), I won't include it.

I have to learn more about tactics and dynamic values of pieces ("bad/good bishops", going to promote pawns) and next about optimize move calculating.

That is how I see it.

Edited by Jakim, 11 July 2011 - 11:19 AM.

  • 0

#14 ihato

ihato

    Destroyed

  • Banned Users
  • 739 posts
  • Version:GM8

Posted 11 July 2011 - 12:26 PM

<Post Destroyed>

Edited by ihato, 22 August 2011 - 12:27 PM.


#15 Jakim

Jakim

    GMC Member

  • GMC Member
  • 28 posts
  • Version:GM8.1

Posted 11 July 2011 - 01:22 PM

I will upload GM8 version soon. At this moment please just import the scripts, should work.
  • 0

#16 Eddygp

Eddygp

    Horizhite Games

  • GMC Member
  • 219 posts
  • Version:GM8

Posted 20 July 2011 - 02:42 PM

It works great with the resources, thanx!
  • 0

#17 Jakim

Jakim

    GMC Member

  • GMC Member
  • 28 posts
  • Version:GM8.1

Posted 30 July 2011 - 11:52 AM

Hi again, I worked some on this engine and I did some features (and gmk file at least!)

Posted Image

Download:

RAR (EXE) - 1.57 MB
GM81
GMK
GML
GMRES
Source: above 40KB. In case of downloading only source, you have to download sprite pack:
images

CHANGES FROM 1.00
- fixed bug with castling
- implemented piece counting
- added algebraic move notation
- added FEN parser
- added very simple PGN parser (importing raw moves)
- added draw by insufficient material
- added drag&drop
- changed design to MODERN (imported from chess.com, hope they don't mind...)

For now there is still slow engine for searching moves and there is no possibility to rewind moves - I think I should fix it before I even try with AI. If you found a bug, let me know!

F2 - save FEN
F3 - load FEN
F4 - save PGN
F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h3 Rf1 76.Kg2 Rf5 77.Bd8 Rf7 78.Bb6 Kd3 79.Bf2 Ke2 80.Bh4 Rg7+ 81.Kh3 Kf3 0-1

Edited by Jakim, 31 July 2011 - 04:21 AM.

  • 0

#18 jon sploder

jon sploder

    GMC Member

  • GMC Member
  • 917 posts

Posted 01 August 2011 - 11:31 PM

Alright, I'm very interested in this and as I am at school, I can only look at the source code rather than run it, so I'm going to scroll through for an ineffeciencies, or things that look odd.

scr_variables_initilize:
Lines 60-65:
for(i=0; i<=1; i+=1;)
{
  game_rook_left_played[i]=1
  game_rook_right_played[i]=1
  game_king_played[i]=1
}

What's the point of doing that? Surely it would be better to just copy and paste it?

scr_lists_initialize:

for(i=0; i<2; i+=1;)
{
  pawns[i]=ds_list_create()
  knights[i]=ds_list_create()
  bishops[i]=ds_list_create()
  rooks[i]=ds_list_create()
  queens[i]=ds_list_create()
}
Similar to the above, and it's different. Also note that you are not decalring that the variable i is local to that script only, given that this is a chess engine I expect that you will need all of the variables to be localized for speed. (well maybe not in initializing, but for alpha-beta you will, so it's a good habit to get into).

The way you've written the FEN position reader is very well done.

I'd really like to play this, I'll ediut this post when I get home.
  • 0

#19 Jakim

Jakim

    GMC Member

  • GMC Member
  • 28 posts
  • Version:GM8.1

Posted 02 August 2011 - 12:24 AM

Hi, thanks for interesting, I'm open for suggests, solutions or just advices. I've copied for loop and filled with the variables. Well, you're right. Hopefully, it's minor flaw since action occurs once.

I've used brute force (poor "check" checking) to check available moves - it makes engine slow. I'm thinking about some heuristic to use.

Edited by Jakim, 02 August 2011 - 12:31 AM.

  • 0

#20 jon sploder

jon sploder

    GMC Member

  • GMC Member
  • 917 posts

Posted 02 August 2011 - 02:44 AM

Hi, thanks for interesting, I'm open for suggests, solutions or just advices. I've copied for loop and filled with the variables. Well, you're right. Hopefully, it's minor flaw since action occurs once.

I've used brute force (poor "check" checking) to check available moves - it makes engine slow. I'm thinking about some heuristic to use.


Again, I'm still not home now, and I don't even have GM to look through the source so can I ask you a few questions:
How many plies can your engine go to before it becomes incredibly slow?
Are you doing using the alpha/beta pruning technique?
What is the approximate strength of your engine?
What is YOUR approximate strength (just out of curiousity).

A few suggestions if you haven't already done these for heuristics:
Promote checks and forceful combinations first.
Create a 'cut off' for sacrifices or just huge negative values returned from one line of play.
I'm not sure if you really want to 'remember' key moves, I seem to remember that people were experimenting with that recently, but I don't think GM handles variables well enough (I mean GM makes everything a double, even when it could just be a byte).


I'd love to test this engine on basic endgames in which it would be able to play reasonably well. Even if the engine can't play too well, I'm very interested in seeing this program being able to play through a database of games so it would be a useful analysis tool - I'm very keen to run through it when I get home. Please tell me if there is anything you're having trouble with or wish me to do (such as trying to compile an opening database).
  • 0

#21 Jakim

Jakim

    GMC Member

  • GMC Member
  • 28 posts
  • Version:GM8.1

Posted 02 August 2011 - 06:26 AM

How many plies can your engine go to before it becomes incredibly slow?

For now, engine does not respond with any move. But even without it recurrent script checks a lot of worthless moves (at least it works, but I have to change it).

Are you doing using the alpha/beta pruning technique?

I will try to implement it, I have done some tests in my "sandbox".

What is the approximate strength of your engine?

0 - this is what I'm working on, but I don't want to write code before I make sure whether I have optimized every other thing and I have good code plan. Intersection of ideas is the main reason of having unoptimalized code.

What is YOUR approximate strength (just out of curiousity).

Based on few games on chess.com, the system says about 1400, but it's highly overrated.

Edited by Jakim, 02 August 2011 - 06:27 AM.

  • 0

#22 jon sploder

jon sploder

    GMC Member

  • GMC Member
  • 917 posts

Posted 02 August 2011 - 06:39 AM

Alright, I'm at home. I'm not affected, but others are by this - please upload a .zip as well as the .rar (some people don't have both, it'll be easier for them). I really enjoy the fact you've got your source code as a text file online, please keep that. And yeah chess.com is a little overrated, but 1400 is pretty similar to mine, I'm ~1400 on FICS.

Looking at source code right now. I'll continue to post ideas on the source here, but please keep us updated so I don't find the same things you yourself do.

Recommendations: Have an options menu that allows you to decide if sound effects should be on, and have all the 'keys' for a FEN position or otherwise included.
Later, perhaps very later, I could attempt to add basic online support (but to an actual server, such as FICS) - I'm assuming you wouldn't want to bother with this yourself?
An opening move database that tells you the name/variation of the opening line you are using.
Scrolling through the game notation being played on the side.

Anyway, I know I've said a lot and everything is a lot of work, so again, if there is anything that I could help you with, I'm more than happy to try.

Edited by jon sploder, 02 August 2011 - 06:51 AM.

  • 0

#23 Jakim

Jakim

    GMC Member

  • GMC Member
  • 28 posts
  • Version:GM8.1

Posted 02 August 2011 - 06:56 AM

Recommendations: Have an options menu that allows you to decide if sound effects should be on, and have all the 'keys' for a FEN position or otherwise included.

Ok, will be :).

Later, perhaps very later, I could attempt to add basic online support (but to an actual server, such as FICS) - I'm assuming you wouldn't want to bother with this yourself?

That would be cool!

An opening move database that tells you the name/variation of the opening line you are using.

In further plans :).

Scrolling through the game notation being played on the side.

As above :).

Thanks for help, really appreciating.
  • 0

#24 MXQ

MXQ

    GMC Member

  • New Member
  • 13 posts

Posted 02 August 2011 - 05:24 PM

very good example, Jakim
i saw it on GMclan.org but i downloaded it when i saw it on Yoyo :)
thanks, dude!

Edited by MXQ, 02 August 2011 - 05:24 PM.

  • 0

#25 Adequate

Adequate

    GMC Member

  • GMC Member
  • 479 posts

Posted 27 August 2011 - 10:22 AM

AI is the hardest part.
  • 0

#26 jon sploder

jon sploder

    GMC Member

  • GMC Member
  • 917 posts

Posted 24 September 2011 - 05:07 AM

Have you made any more progress on this engine? Are you still planning to, or not anymore?
  • 0

#27 Jakim

Jakim

    GMC Member

  • GMC Member
  • 28 posts
  • Version:GM8.1

Posted 24 September 2011 - 06:06 PM

I haven't time for now. I have also one game to finish.
  • 0

#28 Tyrannosaurus rex

Tyrannosaurus rex

    GMC Member

  • GMC Member
  • 498 posts

Posted 30 January 2012 - 02:27 AM

I haven't time for now. I have also one game to finish.


There seems to be a problem with the GM 8 version of this game. Its says "failed to load graphics."
  • 0

#29 Jakim

Jakim

    GMC Member

  • GMC Member
  • 28 posts
  • Version:GM8.1

Posted 30 January 2012 - 08:46 AM

Strange thing, please try for now the 8.1 version.
  • 0

#30 Tyrannosaurus rex

Tyrannosaurus rex

    GMC Member

  • GMC Member
  • 498 posts

Posted 31 January 2012 - 05:10 AM

Strange thing, please try for now the 8.1 version.


Still getting the same issue in 8.1 version.
  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users