teaching machines

Cribbage Statician – Final Project Brian Kendzior

December 20, 2011 by . Filed under cs491 mobile, fall 2011, postmortems.

My final project was an extension of my databases project – a full featured cribbage board in your pocket with statistics tracking!

I drew up a quick “flow-diagram” in mspaint of the different activities that I used in my project.

As you can see, the flow of getting from the main menu to the game activity is all but constant. The base case of only one player playing is easy because you don’t need to pair up players for teams, and you don’t need to select the order of the players.

For 2-3 players you still don’t need to select a team, but the order must be selected before the game may begin.

For 4 or 6 players one must choose both teams, and order before the game may begin. Note that because players are grouped as teams in the order selection activity, an additional button must be added to flip the ordering of the players.

It wasn’t very surprising that I was going to run into huge issues with intent extras at this stage. Keeping my extras constant between activities was a challenge, and I ended up having to put together some hacks to make transitions more seemless. For example, the select order activity must have the ability to receive extras from both the select players activity and the select team activity. I ended up having to make the extra given by select team (an ArrayList of’s) a much more primitive data type (an array of playerId’s with each two indexes representing teams). This made code readability much worse, and having to basically unpack and pack data into less descriptive data types became a pain.

Finally we’ve reached the main screen. It’s not much right now (would like to eventually implement an actual cribbage-like board, but time sinks due to the above mentioned issues made this a non-option), but it has all the basics. Each team is labeled, with the team members names under the label. Scores are under the labels, and the rest of the vertical space under each team is a vertically oriented progress bar. The progress bar is set with 120 (the total number of points you need to win in cribbage) as it’s max value, and each time points are added the progress bar reflects the changes. Creating a vertical progress bar was easier than I imagined… I found a neat tutorial online that laid it out well, and reused/refactored the code as needed.

To add points (play) cribbage, one presses the menu button to open up a context menu allowing a player to either “peg” points to his/her team; or once the pegging round is over they can continue to “Score” their hands. Scoring order is determined automatically based on who dealt and the order selected by players.

Scoring dialogs continue to come up until scoring reaches the dealer, who will score their hand and then score their crib. Scoring is advanced through another context menu brought up using the menu key.

Gameplay will continue as described until a team’s score is above 120. At this point, a win is registered to the database and the player can return to the home menu.

The other option in the home menu is to view statistics for each player. The database records information on every cribbage game played by each player, and can retrieve interesting overall data for each player. My database model is as follows:

I had to change the model from my original project due to difficulty joining tables together. As it stands, the SQL for retrieving the total points scored for each player is computationally heavy (nested select statements summing all entries). Perhaps in later revisions I will keep a running total of certian statistics to reduce database read lag. I also ran into some strange interface issues which slowly corrected themselves after I reset the emulator/adb connection/deleted the gen directory. I’m hoping most of them are simply emulator issues, but to be sure I’d need to run it on an actual device.

Though I didn’t get to implement some of the bells and whistles that I will eventually want to before releasing this to the public, I did manage to create a completely functional pocket cribbage board with statistics tracking. Some things on my eventual wish-list include: