Skip to main content

A board game in MVVM Part 3b - Commands and Converters

This is a continuation of my experience creating a quick board game in silverlight 5
Original Post
Part 1 - The Model
Part 2 - The AI
Part 3 - The View
Play the Game

Commands allow the user to interact with the game. The basics of the actual gameplay are in 2 commands.

There's obviously several others but these 2 commands constitute the bulk of the actual gameplay. Activating a piece chooses which to move, and clicking a square that is enabled (which we tell the board to handle when a piece is activated) makes the player's move. It's very useful to be able to dictate the type of the CommandParameter and I find it much more useful than some of the other implementations which always pass in "object".

A board game in MVVM Part 3 - The View

This is a continuation of my experience creating a quick board game in silverlight 5
Original Post
Part 1 - The Model
Part 2 - The AI
Play the Game

An important thing to keep in mind when looking at the UI here is that I'm following the MVVM design pattern. I didn't want to be manipulating anything in code-behind. The code-behind for the entire game board here is simply:

A board game in MVVM Part 2 - The AI

This is a continuation of my experience creating a quick board game in silverlight 5
Original Post
Part 1 - The Model
Play the Game

AI Thinking Image

The AI code was already included in the source supplied from the previous post in "The Model". The idea was to use minimax with alpha-beta pruning. This was pretty difficult for me because it'd been so long since I'd done any AI. I wanted to get at least 3 steps into a minimax tree. After completion, that's about all I could do. Any deeper took unreasonably long wait time especially if the AI is playing as the attacker (more moves to consider).

A board game in MVVM Part 1 - The Model

This is a continuation of my experience creating a quick board game in silverlight 5
Original Post
Play the Game

I planned on using MVVM so I began the process by breaking down the individual pieces into how they exist in the rules and how they are displayed. I came up with the following:

  • Square
  • Piece
  • Board
  • Game

The board is made up of squares and squares have pieces on them. The game manages the back-and-forth flow of the game. I knew I wanted an AI to be able to use the board, pieces and squares, but wanted it to use separate objects that could potentially reduce overhead so I started by creating interfaces for them defining the properties I knew would be needed. I'm going to use "Square" as a representation of how I went about doing this and why. Here's an example of the interface for Square:

Game-in-a-day

Well, sort of...

I did this game over a period of several days. Altogether the actual time spent on it adds up to about 18 hours so that's why I'm calling it a "Game-in-a-day" even though most of the references I've seen to it actually use a contiguous 24-hour period. Over the next few days I intend on posting about the process I went through, my approach to the problems as well as my solutions. This doesn't have all the bells and whistles of a modern video game or the polish that would be there with a couple weeks of work. This was a quick, one-off project that provided a bit of practice and hopefully is a learning experience for others as well.