AutoHotkey Community

It is currently May 27th, 2012, 12:04 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 13 posts ] 
Author Message
 Post subject: AHK Chess
PostPosted: January 5th, 2011, 6:10 pm 
Offline

Joined: October 11th, 2010, 12:30 pm
Posts: 406
Hello dear AHK community. I should say that I'm just a beginner, I want to make a chess program with AHK. We have enough resources for that.
SKAN's PicturePuzzle0.9a is a very good example for board game makers.
I moded it for my needs, so to speak I plundered it :oops: I have many problems to overcome now, I almost know nothing :(
My idea is to bind Crafty's DOS chess engine to SKAN's PicturePuzzle0.9a gui that I moded. For the time being I can move the pieces but I should apply rules to pieces such as castling for king and rook and diagonal moves for bishops and so on. I don't know how to exchange parameters between chess gui and Crafty engine. I even couldn't replace board background correctly :( I trust you famous AHK coders, please help
Here is my project : http://www.autohotkey.net/~kenn/mychessproject.rar
to see the chess pieces click on board :cry:
P.S. Please don't laugh at me :oops:


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 5th, 2011, 8:56 pm 
Offline

Joined: June 8th, 2006, 9:38 pm
Posts: 307
I think Crafty implements the Winboard protocol - you could probably use that (works via stdin/stdout).


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 5th, 2011, 9:21 pm 
Offline

Joined: October 11th, 2010, 12:30 pm
Posts: 406
Roland, thanks for being so kind as to reply me. I began to feel that nobody was interested in my post. Did you take a look at my project? How can I replace board image behind the pieces?


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 5th, 2011, 9:52 pm 
Offline

Joined: June 8th, 2006, 9:38 pm
Posts: 307
Just use BackgroundTrans for the pieces (see docs for "Gui, Picture"). Plus you'll have to adjust the size of the background so that each square is the same size as a piece.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 5th, 2011, 10:15 pm 
Offline

Joined: March 11th, 2010, 7:29 am
Posts: 177
Location: glendale, az
nice widipedia board and pieces! lol! i don't mean to make fun. honestly, i used those same pieces too for a while to print out problem sheets untill i started using chessbase instead! for me the quality of the image when printed 9 boards to a page on paper was the most important thing otherwise i'd still be using that!

anyways, i'm not much help but i'll do what i can! i'm excited to see your project and i hope it works out well! if you'd like we could maybe work together. i'm no good with most the ahk programming stuff but i can usually figure something out when i need to.

i have some chess tournament software i've been working on but it's not much (yet). if and when i ever get a descent program working and a website i'll put a download page for yours too if you want, so long as i'm able. here's the link to the page with the .exe and the open source, .ahk file. http://www.autohotkey.com/forum/viewtopic.php?t=66571 (my code's not anything super special but feel free to plunder away if there's something you think you can use).

p.s. i don't know if you've seen it yet or if it would help but there's a soduko .ahk script that's pretty interesting that might help you get some ideas.

_________________
2+2 does not equal 3, and 9/11 was a big fat inside job!


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 5th, 2011, 10:39 pm 
Offline

Joined: October 11th, 2010, 12:30 pm
Posts: 406
Roland, thanks I ll try that. I need to look at examples especially ones move controls.
luffy :) I know what you mean, I guessed somebody would notice that. thanks for your post and encouraging words. I want everybody to contribute to this project, we can have a working chess program. As I said I'm only a beginner so don't expect much from me but I'll do my best
By the way I knew your chess tournament program, It's nice, I was intent to use it for my chess club tournament :)


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 6th, 2011, 12:21 am 
Offline

Joined: March 11th, 2010, 7:29 am
Posts: 177
Location: glendale, az
hmmmm... moving controls... now that you mention it i can't remember ever seeing any ahk scripts with any but that doesn't mean that there aren't any out there. i think it would be possible to make a gui window inside a window, possibly 64 of them, one for each square, and redraw the specific windows when triggered. but i've never dabbled with that idea so there's a good chance that's not the best way to go.

i've got a lot of controls in my script that i use for variables just let me know if you need any help with the kind of stuff i've put in my code. that's probably about all i'll ever be good for.

_________________
2+2 does not equal 3, and 9/11 was a big fat inside job!


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 6th, 2011, 12:50 am 
Offline
User avatar

Joined: November 2nd, 2008, 4:23 pm
Posts: 2906
Location: 127.0.0.1
You can make 64 picture controls and assign a picture to each. Instead of moving them you can just change all the pictures to represent the current board state.

You will want to use the v option on each picture control so you can change it with GuiControl (see picture option).
You can use an array (see Object() in help) to hold the current board state and check possible moves.

_________________
aboutscriptappsscripts
Any code ⇈ above ⇈ requires AutoHotkey_L to run


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 6th, 2011, 4:31 am 
Offline

Joined: January 15th, 2007, 2:37 pm
Posts: 573
I don't know all the rules of chess but I did have an idea for you. I've uploaded an example so you could look and see if it's close to what your looking for.

http://www.autohotkey.net/~specter333/Misc/Chess.zip
Image

And here the script.
Code:
p1dis = square63
p2dis = square64

Gui, Add, Pic, x0 y0 vsquare11 gsquare, black.jpg
Gui, Add, Pic, x50 y0 vsquare12 gsquare, white.jpg
Gui, Add, Pic, x100 y0 vsquare13 gsquare, black.jpg
Gui, Add, Pic, x150 y0 vsquare14 gsquare, white.jpg
Gui, Add, Pic, x200 y0 vsquare15 gsquare, black.jpg
Gui, Add, Pic, x250 y0 vsquare16 gsquare, white.jpg

Gui, Add, Pic, x0 y50 vsquare21 gsquare, white.jpg
Gui, Add, Pic, x50 y50 vsquare22 gsquare, black.jpg
Gui, Add, Pic, x100 y50 vsquare23 gsquare, white.jpg
Gui, Add, Pic, x150 y50 vsquare24 gsquare, black.jpg
Gui, Add, Pic, x200 y50 vsquare25 gsquare, white.jpg
Gui, Add, Pic, x250 y50 vsquare26 gsquare, black.jpg

Gui, Add, Pic, x0 y100 vsquare31 gsquare, black.jpg
Gui, Add, Pic, x50 y100 vsquare32 gsquare, white.jpg
Gui, Add, Pic, x100 y100 vsquare33 gsquare, black.jpg
Gui, Add, Pic, x150 y100 vsquare34 gsquare, white.jpg
Gui, Add, Pic, x200 y100 vsquare35 gsquare, black.jpg
Gui, Add, Pic, x250 y100 vsquare36 gsquare, white.jpg

Gui, Add, Pic, x0 y150 vsquare41 gsquare, white.jpg
Gui, Add, Pic, x50 y150 vsquare42 gsquare, black.jpg
Gui, Add, Pic, x100 y150 vsquare43 gsquare, white.jpg
Gui, Add, Pic, x150 y150 vsquare44 gsquare, black.jpg
Gui, Add, Pic, x200 y150 vsquare45 gsquare, white.jpg
Gui, Add, Pic, x250 y150 vsquare46 gsquare, black.jpg

Gui, Add, Pic, x0 y200 vsquare51 gsquare, black.jpg
Gui, Add, Pic, x50 y200 vsquare52 gsquare, white.jpg
Gui, Add, Pic, x100 y200 vsquare53 gsquare, black.jpg
Gui, Add, Pic, x150 y200 vsquare54 gsquare, white.jpg
Gui, Add, Pic, x200 y200 vsquare55 gsquare, black.jpg
Gui, Add, Pic, x250 y200 vsquare56 gsquare, white.jpg

Gui, Add, Pic, x0 y250 vsquare61 gsquare, white.jpg
Gui, Add, Pic, x50 y250 vsquare62 gsquare, black.jpg
Gui, Add, Pic, x100 y250 Disabled vsquare63 gsquare, white.jpg
Gui, Add, Pic, x150 y250 Disabled vsquare64 gsquare, black.jpg
Gui, Add, Pic, x200 y250 vsquare65 gsquare, white.jpg
Gui, Add, Pic, x250 y250 vsquare66 gsquare, black.jpg

Gui, Add, Pic, x100 y250 BackgroundTrans vpiece1 gselpiece, piece1.png
Gui, Add, Pic, x150 y250 BackgroundTrans vpiece2 gselpiece, piece2.png

Gui, Add, Pic, x-50 y0 BackgroundTrans vmark, marked.png

Gui, Show, y10 w300 h300, Chess Example
Return

selpiece:
Gui, Submit, NoHide
selected = %A_GuiControl%
GuiControlGet, piecepos, Pos, %selected%

Return

square:
Gui, Submit, NoHide
moveto =  %A_GuiControl%
GuiControlGet, squarepos, Pos, %moveto%
If selected =
   Return
GuiControl, Move, mark, x%squareposx% y%squareposy%
GoTo movepiece
Return

GuiClose:
Gui, Destroy
ExitApp

movepiece:
MsgBox, 4, , Move %selected% to %moveto%?
IfMsgBox, No
   {
   GuiControl, Move, mark, x-50 y0
   moveto =
   Return
   }
IfMsgBox, Yes
   {
   GoSub %selected%
   GuiControl, Move, mark, x-50 y0
   GuiControl, Move, %selected%, x%squareposx% y%squareposy%

   
   }

selected =
moveto =
Return

piece1:
If pieceposx = %squareposx%
   {
   GuiControl, Enable, %p1dis%
   GuiControl, Disable, %moveto%
   p1dis = %moveto%
   Return
   }
   
If pieceposy = %squareposy%
   {
   GuiControl, Enable, %p1dis%
   GuiControl, Disable, %moveto%
   p1dis = %moveto%
   Return
   }

MsgBox, This Piece can only move horizontally or vertically.`nPlease try again.
moveto =
selected =
GoTo = selpiece
Return


For this to work you would have to be a math wiz and create a rule for every chess piece. I only made a rule for the "O" piece to move horizontally or vertically, the other piece doesn't move. I should also point out that I didn't make any rules for taking other pieces, only moving a piece around the board.

Notice each square's variable has it's position on the board, ie. square35 is x3 y5, this makes it easy to keep track of what square is being selected. Also every square the piece is sitting on when the game begins needs to be disabled and a variable assigned as to what piece is disabling (sitting on) so it can be enabled when the piece moves.

I think this will get you started if you can write all the rules for each piece and develop a method to change turns when a player moves. That last part should be easy, all the rules will be a challenge.

Good Luck


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 6th, 2011, 7:05 am 
Offline
User avatar

Joined: September 5th, 2009, 2:06 pm
Posts: 1718
Location: Somewhere near you
Is it a human vs human, or human vs AI?

_________________
Image
The quick onyx goblin jumps over the lazy dwarf


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 6th, 2011, 7:10 am 
Offline

Joined: June 12th, 2009, 11:36 pm
Posts: 1173
Location: Indianapolis IN, USA
tomoe_uehara wrote:
Is it a human vs human, or human vs AI?
A Chess AI for AHK would be thousands of lines long. One that is even worth playing that is.

_________________
www.AutoHotkey.net/~Eedis
I love my wife and daughter so much.
Image


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 6th, 2011, 3:25 pm 
Offline

Joined: October 11th, 2010, 12:30 pm
Posts: 406
Hello guys, I just had an opportunity to check out the posts, thanks a lot for your contributions, views and supports.

Spectre333, thanks for nice chess gui and idea, it's another approach to move the pieces, I ll check it out carefully.

tomoe_uehara, it will have both options, human vs human and human vs AI, remember we have free chess AI's such as Crafty, Rybka.. I put Crafty engine in my project, but we must implement it via stdin/stdout functions as Roland suggested.

Frankie, thanks a lot! Your tip is one of the best, I needed to know that. You grasped the essence of it, as to me you can lead this project, what do you think? Do you have enough time to spend on this?


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 6th, 2011, 8:20 pm 
Offline
User avatar

Joined: November 2nd, 2008, 4:23 pm
Posts: 2906
Location: 127.0.0.1
Quote:
Do you have enough time to spend on this?
Sorry, no.

_________________
aboutscriptappsscripts
Any code ⇈ above ⇈ requires AutoHotkey_L to run


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 13 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: BrandonHotkey, Google Feedfetcher, Yahoo [Bot] and 19 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group