Skip to main content
GameDev.net gamedev.net
🔒 Locked

Chess program using vb.net

Started by Paul Orton Jan 6, 2007 at 3:20 PM 11 replies 10.2k views
Original Post
Paul Orton
Paul Orton
Does anyone know of any good chess programming links (ideally in vb.net)? I only want to get some ideas of how such a program should be structured just to get me started - I don't want to waste my time going down blind alleys (for instance, there are many ways to represent a chessboard and pieces but apparently 'bitboards' are the only sensible way to go. I wouldn't want to discover that the hard way!). Paul.
Crazyfool
Crazyfool
Ok, if you want a multiplayer game over internet.. WinSock is rediculously easy with VB, and I think in VB.net as well.

Chess in VB will actually be an easy yet manageable game for a beginner.

How I'd do it is (I havent done VB for a while) make an UDT, or class if VB.net has those, representing the chess board with characteristics describing it. I'd also make a UDT/class for the gfame pieces.. such as art location and move style.. like, how I'd manage the move style is make my own ways of writing and processing the moves..

ex: a pawn might look like this: 1.2. meaning it can move 1 or 2 (I think those are rules for chess?

a knight might look like: 3,2.

My protocol means a . represents end of possible move, and comma represents the 2nd direcxtion.. i.e., first number means first direction then the 2nd number does a diff direction/.

Of course, that might be unneccesary as you'd still need to hard program a lot of them, like the diagonal guy, the queen and the restrictions on which direction (pawns can only move forward/and diagonal?)

Oh man I just reealized I dont know much about chess.

Anyway, after you do that, you can make an array of objects, squares, with all the same name, which are internally represented by the UDT/class you created.. then when the user clicks on the VB form object, you can check the index to see which object you have to check for which game piece is there if any.. then you can dispplay the possible move choices by changing the color of legal move spaces.

Once they choose a proper space, you can move it, handle any game pieces that should be removed (and stored in some containert, cause cant players get lost pieces back? or is that only checkers?) then inform the next player its their turn.

I THINK that's roughly how I'd do it.. though I am not reeally planning it out too much, I'm a bit tired, and I dont know the rules of chess that well.. so if I am missing certain rules that would affect the design process.. sorry, but hopefully this is better than nothing ;)
Crazyfool
Crazyfool
er, as for representing a chess board.. hm.. never heard of a bitboard.. but I'd use a double array or whatever the term is ;)

Dim Square[8][8] as SuperCooLSquareObject (is that how you still declatre variables? lol.. also is it 8x8? )

Stormtrooper30
Stormtrooper30
Quote:
Original post by Crazyfool
er, as for representing a chess board.. hm.. never heard of a bitboard.. but I'd use a double array or whatever the term is ;)

Dim Square[8][8] as SuperCooLSquareObject (is that how you still declatre variables? lol.. also is it 8x8? )


Aye, it is infact 8x8.

pawns go forward 1 or 2 on first move, 1 for rest of game. When taking, pawn moves diagnol. When pawn reaches the other end of board, player picks what piece it will turn into (usually a queen)

rook goes horizontal or vertical

knight goes (counting starting point) 3 horizontal/vertical (counting each square once). Then one aditional square horizontal/vertical. (Can pass over pieces)

bishop goes diagnol

queen goes in all directions

king goes in all directions 1 square.
Paul Orton
Paul Orton
Quote:
Original post by Crazyfool
er, as for representing a chess board.. hm.. never heard of a bitboard.. but I'd use a double array or whatever the term is ;)

Dim Square[8][8] as SuperCooLSquareObject (is that how you still declatre variables? lol.. also is it 8x8? )


A bitboard (or bitmap) is simply a 64 bit word in which you state the presence (1) or absence (0) of a certain type of piece. Hence you would have multiple bitmaps, one for white pawns, one for black pawns etc. etc.

It's supposed to be much more efficient than an 8x8 array although much harder to get your head around apparently.

Paul
Paul Orton
Paul Orton
Quote:
Original post by Crazyfool
I THINK that's roughly how I'd do it.. though I am not reeally planning it out too much, I'm a bit tired, and I dont know the rules of chess that well.. so if I am missing certain rules that would affect the design process.. sorry, but hopefully this is better than nothing ;)


Thanks for giving that so much thought - much appreciated!

I'm actually looking to build a chess engine ie. a program that will play humans.
I'm a reasonably good player myself so I know the sort of 'skills' to put into an engine - the problem is *how* to put them in via code!

So it's really just a learning exercise (but a massive challenge, too!).

Paul
Christer Ericson
Christer Ericson
Quote:
Original post by Crazyfool
er, I'd be willing to bet having a map with 64 different things to run through, for each game piece would NOT be more efficient.
You'd lose that bet, as bitboards is what most (if not all) the big chess programs use these days (and have for some time), for reasons of efficiency and cleanness of design. For more info, see this article about board representations by Bob Hyatt of Crafty fame. Note that the article is at least about 3+ years old so these days things have swung even more in favor of bitboards (due to e.g. increased memory bottlenecks and more 64-bit machines).

BTW, Bob Hyatt has other interesting papers available here: http://www.cis.uab.edu/hyatt/pubs.html.

Quote:
Making a class/UDT to represent game pieces is a must!
Not really.

The source for Crafty is publicly available, and anyone that is seriously interested in writing a chess program could do worse than download and study the code to get some ideas about how you structure your code to write a world-class chess program.

Of course, if someone just want to tinker a little, it really doesn't much matter what they do.
sharpnova
sharpnova
Quote:
Original post by Crazyfool
er, I'd be willing to bet having a map with 64 different things to run through, for each game piece would NOT be more efficient.


dead wrong. logical operations being done on bits makes it very nice for doing searches for threats, checks, captures, etc. the top engines use bit boards. nothing else comes close.

Quote:
Besides, we're talking chess here. You could almost program this the worst possible way and it still wouldnt come close to hurting the speed of yuor play on any computer made within 5 years ;)


also dead wrong. you have to optimize the hell out of a chess engine to get good play. because the branching factor is high even with good pruning and processors made within the last 5 years are nowhere NEAR fast enough to make chess trivial.

Quote:
Anyway, why would you do something that would give yuou such a minor performance boost when if it is hard to grasp (I understand it fine, but I might be missing some points) or if it just takes extra time.


no offense but it doesn't seem like you grasp it at all.

Quote:
There's really no need to use something like this, and in fact, I think it goes against many programming standards.. for instance..


sigh.. chess programming is a huge subset of computer science. please do some research. you're trying to influence someone who is trying to learn without having the foggiest idea what you're talking about.

that is just plain unprofessional.

Quote:
let's say there's 10 types of peices (im sure there's less, but bare with me), and then if you want to move, you have to check if its a legal move, so you have to check every other bit map for BOTH players, and THEN move. ok, so you make a new "whole" bit map, that uses 0 for empty, 1 for one team and 2 for another team.


i would educate you about this but since you didn't take the time to do any real research before trying to tell an aspiring chess programmer that tried-and-true solid conventions are bad, i really doubt you'd want to hear it anyways. but if you're willing, i suggest you look into it a bit. there is a lot more to it than you realize. are you even familiar with the mini-max algorithm?
Everyone hates #1.That's why a lot of idiots complain about WoW, the current president, and why they all loved google so much when it was new.Forget the fact that WoW is the greatest game ever created, our president rocks and the brainless buffons of America care more about how articulate you are than your decision making skills, and that google supports adware, spyware, and communism.
Crazyfool
Crazyfool
Well, it looks like I DIDNT understand. I was under the impression of something completely different.

Anyway, I am a bit embaressed and I wont give any more advice :(

To try and save as much face as possible, I truly was not even thinking of what they are, and was thinking of a user created type that a programmer created themselves, sorta like a class with the desired data entries.

:(


Edit: and woa man, it was an honest mistake. I warned several times in my posts I could be wrong and I dont even know chess that well.

I was also planning for a chesst 1v1 multiplayer game, not with AI, in which case NO, speed would NOT be an issue. Chess with an AI, you're certainly right.

Youre acting as if I tried to sabotauge him, you can check my post record and I ask for tons of help and give it when I can.. and I tried my best, dont need to be such a prick :P


Edit again: and wouldnt VB.net be somewhat of a bottleneck? Why not do it in LISP or something similiar? From what I hear, LISP is a very strong AI language, and LISP also offers and immense amount of versatility.
powerskill
powerskill
Sounds like a fun project. I wish to make a chess game myself but I think theres much more learning to be done before that :)
Good luck

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.