05 December 2009

Moving pieces

I captured the mouse position and added the ability to select a piece to move, checking, of course, that it was a legal move.

This was easy to add as all the game logic for deciding legality of moves already existed in the console app. This was partly why I wanted to get the game play sorted out in a console app before trying to tackle XNA.

04 December 2009

Searching the rainforests

If you have been using Bing or Yahoo for search, consider using Ecosia instead.

It's a search engine created by the WWF in conjunction with Yahoo and Bing. It has the advantage that most of the money taken from advertising goes to protect the rainforest. According to the search page they have already managed to protect 108,000 square yards. The more people use the search engine the faster that figure will grow.

Obviously, it isn't enough and what is really needed is for Governments to act. I know small changes are not enough, but it is time to do whatever we can.

XNA Conference

Tomorrow is the first XBLIGUK conference in Birmingham, for XNA developers. I am not going to be there, but I hope it is a success and that it is the first of many. The agenda looks very promising.

02 December 2009

Putting the code into XNA, part 2

I added a GameMode class to handle the succession of different modes that happen within the game, starting with the following :-

Player 1 rolls the dice,
Player 1 enters a move,
Make player 1's first move,
Player 1 enters second move,
Make player 1's second move,
Player 2 rolls the dice,
Player 2 generates 2 moves,
Make player 2's 1st move,
Make player 2's 2nd move

After player 2 has moved the game loops back to player 1's turn.

I found it best to keep to keep the Draw method just for displaying the board and all the changes to the gamemode in the Update method of the game loop.

So the game Update method contains a switch statement similar to this...

switch (GameMode.State)
{
case GameMode.Player0RollingDice:
{
Dice.Roll();
GameMode.State = GameMode.Player0Input1;
break;
}
case...

01 December 2009

Putting the code into XNA


I started by getting XNA to display the board, this is easy
as it is just a static background so I used the spriteBatch.
Vector2 tempVector = new Vector2(0, 0);
spriteBatch.Draw(background, tempVector, Color.White);

I also needed to resize the window in the Initialize() method...
this.graphics.PreferredBackBufferWidth = 224;
this.graphics.PreferredBackBufferHeight = 471;
this.graphics.ApplyChanges();

Then display the pieces on the board in their starting positions and finally the dice. It is only a 2d game but this seems really easy.
I needed to get mouse input. I used Mouse.GetState().
If the game was ever going to run on the XBox then this wouldn't be enough. Apparently they forgot to add a mouse when they designed the XBox. What were they thinking? I'd need to add support for a GamePad. I don't own an XBox so I am not too bothered about this.

KeyboardState keyboard = Keyboard.GetState();
MouseState mouse = Mouse.GetState();

Now, I can use mouse.X, mouse.Y and compare mouse.LeftButton with ButtonState.Pressed.

29 November 2009

Alpha beta tree pruning

A method where you can limit the number of nodes that the computer looks ahead in a game by stopping if you can prove that a particular move would be worse than one you have already evaluated. I think.

The wikipedia article leads me to conclude that some people
have spent a lot of time thinking about games.

Maybe next time I write a game I'll use it.