My Chess Program

Anything related in any way to game development as a whole is welcome here. Tell us about your game, grace us with your project, show us your new YouTube video, etc.

Moderator: PC Supremacists

User avatar
dandymcgee
ES Beta Backer
ES Beta Backer
Posts: 4709
Joined: Tue Apr 29, 2008 3:24 pm
Current Project: https://github.com/dbechrd/RicoTech
Favorite Gaming Platforms: NES, Sega Genesis, PS2, PC
Programming Language of Choice: C
Location: San Francisco
Contact:

Re: my chess Program

Post by dandymcgee »

Looks like it's coming along nicely. The checkmate display is rather strange. All of the pieces appear to work as suspected.
Falco Girgis wrote:It is imperative that I can broadcast my narcissistic commit strings to the Twitter! Tweet Tweet, bitches! :twisted:
User avatar
cndr
Chaos Rift Cool Newbie
Chaos Rift Cool Newbie
Posts: 65
Joined: Sat Apr 24, 2010 7:03 am
Programming Language of Choice: etc.

Re: my chess Program

Post by cndr »

I'm think I might be changing all the graphics pretty soon, I didn't really know what to do for checkmate so I just whipped that together. I was playing around with the program this morning and found out that I totally forgot that pinned pieces can't stop checkmate, so the program doesn't recognize checkmate when a piece is pinned to the king, and it would normally be able to stop the check. It looks like I have a little bit more work before I can continue.
Long Live The Queen!
User avatar
cndr
Chaos Rift Cool Newbie
Chaos Rift Cool Newbie
Posts: 65
Joined: Sat Apr 24, 2010 7:03 am
Programming Language of Choice: etc.

Re: My Chess Program

Post by cndr »

when I run my chess program I notice that atleast 1 of my cpu's is at 100%, I ran the program with valgrind, the summary is as follows:

The heap summary is way too long to post but if you are interested in it here is a link http://www.box.net/shared/sn0c2vsmp0

leak summary and error summary:

Code: Select all

==3154== LEAK SUMMARY:
==3154==    definitely lost: 114 bytes in 4 blocks
==3154==    indirectly lost: 304 bytes in 7 blocks
==3154==      possibly lost: 1,335,280 bytes in 2 blocks
==3154==    still reachable: 121,181 bytes in 1,334 blocks
==3154==         suppressed: 0 bytes in 0 blocks
==3154== 
==3154== For counts of detected and suppressed errors, rerun with: -v
==3154== ERROR SUMMARY: 5 errors from 5 contexts (suppressed: 268 from 8)

I think the possibly lost bytes might be a problem
Long Live The Queen!
User avatar
Ginto8
ES Beta Backer
ES Beta Backer
Posts: 1064
Joined: Tue Jan 06, 2009 4:12 pm
Programming Language of Choice: C/C++, Java

Re: My Chess Program

Post by Ginto8 »

cndr wrote:when I run my chess program I notice that atleast 1 of my cpu's is at 100%, I ran the program with valgrind, the summary is as follows:

The heap summary is way too long to post but if you are interested in it here is a link http://www.box.net/shared/sn0c2vsmp0

leak summary and error summary:

Code: Select all

==3154== LEAK SUMMARY:
==3154==    definitely lost: 114 bytes in 4 blocks
==3154==    indirectly lost: 304 bytes in 7 blocks
==3154==      possibly lost: 1,335,280 bytes in 2 blocks
==3154==    still reachable: 121,181 bytes in 1,334 blocks
==3154==         suppressed: 0 bytes in 0 blocks
==3154== 
==3154== For counts of detected and suppressed errors, rerun with: -v
==3154== ERROR SUMMARY: 5 errors from 5 contexts (suppressed: 268 from 8)

I think the possibly lost bytes might be a problem
make sure that you have just as many deletes as you have news. If something is allocated and then not deallocated it will cause a lot of memory issues... but that isn't what's eating up your CPU. I think it might be that you forgot to limit the framerate.
Quit procrastinating and make something awesome.
Ducky wrote:Give a man some wood, he'll be warm for the night. Put him on fire and he'll be warm for the rest of his life.
User avatar
cndr
Chaos Rift Cool Newbie
Chaos Rift Cool Newbie
Posts: 65
Joined: Sat Apr 24, 2010 7:03 am
Programming Language of Choice: etc.

Re: My Chess Program

Post by cndr »

wow, I never even thought about limiting the frame rate. I'll get working on that, and I'll update you when I have it implemented, it wont be until tomorrow I think.
Long Live The Queen!
User avatar
Ginto8
ES Beta Backer
ES Beta Backer
Posts: 1064
Joined: Tue Jan 06, 2009 4:12 pm
Programming Language of Choice: C/C++, Java

Re: My Chess Program

Post by Ginto8 »

well if you need something to look at, I really liked this tutorial when I first started framerate limiting: http://www.lazyfoo.net/SDL_tutorials/lesson14/index.php
Quit procrastinating and make something awesome.
Ducky wrote:Give a man some wood, he'll be warm for the night. Put him on fire and he'll be warm for the rest of his life.
User avatar
cndr
Chaos Rift Cool Newbie
Chaos Rift Cool Newbie
Posts: 65
Joined: Sat Apr 24, 2010 7:03 am
Programming Language of Choice: etc.

Re: My Chess Program

Post by cndr »

thanks for the link Ginto8, I've been messing around with lazy foo's timer class, and made this program this afternoon, I don't know if its worthy of entering moosaders competition, but it is pretty retarded. here is the link for windows users http://www.box.net/shared/24s8kisqj2. if anyone is interested in the Linux version of it, I'll post it.

Long Live The Queen!
User avatar
cndr
Chaos Rift Cool Newbie
Chaos Rift Cool Newbie
Posts: 65
Joined: Sat Apr 24, 2010 7:03 am
Programming Language of Choice: etc.

Re: My Chess Program

Post by cndr »

well I have the frame rate limiter working in my chess program, but I am still having problems with how much cpu usage it uses, I made a video to show off the board editor I added, it doesn't show off loading and saving because I forgot to include it, but the program can do it. In the video I also show that the program stays steadily over 90% cpu usage. I must have a memory leak somewhere, I'm going to look into it, heres the video.

Long Live The Queen!
Live-Dimension
Chaos Rift Junior
Chaos Rift Junior
Posts: 345
Joined: Tue Jan 12, 2010 7:23 pm
Favorite Gaming Platforms: PC - Windows 7
Programming Language of Choice: c++;haxe
Contact:

Re: My Chess Program

Post by Live-Dimension »

Growing memory usage signifies a memory leak, not a high CPU usage.

Chess programs by definition are CPU-usage hogs.
Image
User avatar
cndr
Chaos Rift Cool Newbie
Chaos Rift Cool Newbie
Posts: 65
Joined: Sat Apr 24, 2010 7:03 am
Programming Language of Choice: etc.

Re: My Chess Program

Post by cndr »

I think the bit boards is taking up more space than is needed, since I have them in a class I decided to make them private, and have another bit board outside the class that represents the data. Right now I have 117 bit boards all with a size of 144, so that would take up 16848 bytes. If I make the bit boards I can cut them down to 63, cutting the bytes down to 9072. I believe this might be some sort of solution, another thing I could do is keep them all private and only use them inside the class, I think I'll go for that approach first.
Long Live The Queen!
User avatar
cndr
Chaos Rift Cool Newbie
Chaos Rift Cool Newbie
Posts: 65
Joined: Sat Apr 24, 2010 7:03 am
Programming Language of Choice: etc.

Re: My Chess Program

Post by cndr »

I finally finished removing all the unnecessary bit boards, my program now uses 11.5 MiBs of memory, I believe before it was around 13. Since I don't use a number higher than 1000 I changed all my ints to shorts, there wasn't that many so there was hardly a difference but that should give me some more space to play with later on. I still have to deal with that cpu usage problem.
Long Live The Queen!
User avatar
cypher1554R
Chaos Rift Demigod
Chaos Rift Demigod
Posts: 1124
Joined: Sun Jun 22, 2008 5:06 pm

Re: My Chess Program

Post by cypher1554R »

The CPU usage problem usually occurs at bad looping methods and no vsync.

Try to refresh the screen (call Display() fuction) only when a move is made.
User avatar
cndr
Chaos Rift Cool Newbie
Chaos Rift Cool Newbie
Posts: 65
Joined: Sat Apr 24, 2010 7:03 am
Programming Language of Choice: etc.

Re: My Chess Program

Post by cndr »

last night I found out the problem, I had the graphics and the calculations of the bit boards in the game loop updating as much as possible, I did a test I ran the program for roughly 10 seconds at a frame rate of 13 seconds, the program looped through 131 times, 13 times a second, as expected, 126000 bytes called to store the bit boards alone every second. I'll be updating the program soon, I'm going to start working on the checkmating system again, haven't actually worked on that in a while. I was playing around with SDL_WaitEvent(), I like how it puts the program to sleep, but the only way to exit the program is to esc out of it, I just had it in the main loop, but I'm sure there is a better way to handle it, I think I might come back to it in the future, I'll look deeper into it once I have this game actually working.
Long Live The Queen!
pythip
Chaos Rift Newbie
Chaos Rift Newbie
Posts: 33
Joined: Sat Apr 24, 2010 11:25 pm

Re: My Chess Program

Post by pythip »

have you thought about going open source so we can see how exactly you do things?
User avatar
cndr
Chaos Rift Cool Newbie
Chaos Rift Cool Newbie
Posts: 65
Joined: Sat Apr 24, 2010 7:03 am
Programming Language of Choice: etc.

Re: My Chess Program

Post by cndr »

I'm not sure how much you can learn from my code, but if enough people are interested I'll release it, but for the mean time I have a new release, I should note that some functions aren't working 100% in windows, like loading and saving, seems like windows puts cout to file, which is kinda annoying, I'm going to have to go to lazy foo's site, and do a lesson on displaying text, and inputing text. I'm pretty sure I have checkmate working now, I'm going to be doing some more testing on it, so far it seems like I have to select a piece on the person who is checkmated turn for the checkmate message to appear, I'm going to have to give some credit to people in this version because I've temporarily used other peoples functions, I borrowed lazy foos timer class, and I learned collision detection from moosader. I should also say that the promoting piece is the piece that is out of board, the box around it is just temporary graphics for it, I'm still working on that. If you find bugs please report it, I hope to have another update soon.

EDIT: the game freezes in windows when you try to load, I didn't test for saving.
Long Live The Queen!
Post Reply