views:

109

answers:

2
Hello, I have homework in **c#**. I have to make a game (such as checkers, chess or something else, but not tic tac toe - and I choose checkers/draughts) with using **minimax** and **alphabeta**, but I don't even know how to start :( **And I have a tight deadline**. I worked with c# a little bit at school, but I'm not a programmer. Now I'm trying to make an array, that will be represent a board and positions of its pieces. What is better? If the information about positions of pieces and their values will be saved with the board or if these informations will be saved for each piece separately. And how to make the best array for this. Basically what i need is an advice how to start, how to represent the game state - the basic structure of the program etc. If anybody can help me, please, write me. Thanks for any help. Washa
+1  A: 

Hint: use a 2 dimensional array to represent your game board:

int[,] board = new int[8, 8];
Dan
Thanks, I already started with the same array and now I'm making the generating of pieces on board...
Washa
does it need to be 8x8 in memory? the Men can only stand on 32 squares......
Adrian
It's a homework assignment, so I wouldn't go for the most optimized solution. Keep it understandable. So, when you are coding checkers, and you are on location 2,0, you know that you can move to 1,1 or 3, 1. If you keep it 4x4, then you have to remember which row is shifted which direction and you can make a mistake much easier. Use the int in each space so you know what is there. For example, 0 is empty. 1 is red, 2 is red king, 11 is black, 12 is black king.
Dan
Adrian, Dan, thanks, I choose 8x8 model, because it's more understandable, as You said...
Washa
+1  A: 

The standard method for storing the board state is to use bitboards.

public class Board
{
  private UInt64 m_RedPieces = 0x0000000000559955; // Initial position;
  private UInt64 m_BlackPieces = 0x9955990000000000; // Initial position;
}

The cool thing about bitboards aside from the fact that they are super fast is that it makes generating legal successor positions much easier. It is still hard mind you, but with bitboards you can reduce the move geneneration to a series of bit operations (shifts, ANDs, ORs, XORs, etc.).

I am sure there are a lot of resources already out there on the internet that have the formulas for working with the bitboards.

Brian Gideon
thanks, but I think this is too much difficult for me and my skills :(
Washa
@Washa: Not necessarily. I think you may actually find it easier. For example, to generate all successor positions from the initial position you start by shifting `m_RedPieces` left 7 bits and XORing `m_RedPieces` to remove the squares already occupied by red pieces. There are a couple of more details involved here, but you get the idea. You will add more and more bit operations to catch the other scenarios including jumps, not moving into a square occupied by opponent pieces, etc. I think you will actually find this easier than crafting a series of `if-else` blocks.
Brian Gideon
Brian, yes, You're definitely right, but I'm afraid about this... I never use these operations as XOR, OR etc in c# or anywhere else. Maybe long time ago and only in theory (lesson at school but not programming subject) :(
Washa
I'm not sure this is a good option - how would you have Kings?
Adrian
You would have to have a king bitfield as well.
Brian Gideon