My inspiration for this lab came from cs302 lab5 - Superball. In short, Superball is a game where you can swap cells and gain points for cells that connect to a goal cell. I'd suggest looking at Dr. Plank's writeup for more details about the game.
Given a state of a Superball board and some game inputs, the purpose of my program is to find the top 10 swaps that give the best state of the board. Then, the program will list all the swaps in descending order, each with a corresponding JGraph of what the board looks like post-swap.
...yyryy.p y.rg.yppyp **gg.yrpPP GGgbgybp** R*bg.yrp*P G*gygyypY* yyybpby.pb .pgg.yp.bb |
The C++ file takes several parameters on the command line in order to find and display the best swaps for a Superball game board. It takes the board as a text file with the same format as specified in cs302 lab5, and then constructs a nice visual output using JGraph. For all inputs, the program needs:
Only the following colors are supported:
Below is a full example ran with:
...yyryy.p y.rg.yppyp **gg.yrpPP GGgbgybp** R*bg.yrp*P G*gygyypY* yyybpby.pb .pgg.yp.bb |
The dimensions of the board are generated dynamically, based on the height and width of the input board. Each cell is a box marktype at a cetain point and are filled using cfill. The goal cells are marked with the character '*'.
One interesting problem that came up when graphing the board is the way that the board is represented in code versus the graph itself. The board is stored in a vector, so (0,0) is the top left cell of the board. However, when making the graph, (0,0) is the origin. To convert the board to a graph, it had to be rotated 90deg clockwise.
The background of the board is dependent on the post-swap scorable state of the board. Green means it's a good swap, yellow means it's a decent swap, and red means the swap doesn't help out much at all. See scoring for more details on how the score is calculated.
Most of the information given on the command line is displayed on the information menu on the right side of the graph. This is done by drawing a newline poly with a white pcfill. All of the info is then drawn inside it using the newstring attribute. Since the width of the graph depends on the input board, the entire navigation menu also has to be dynamically drawn.
To find which cells are connected, connected components are used instead of disjoint sets. If any part of the component is in a goal cell and it is greater than the mss, the component is marked with an orange background on the graph. In JGraph, this background around the marker is a line that is drawn around cell.
For scoring, only the components that can be scored are considered. This is the score that is presented in the blue box on the information menu. Perhaps there's better scoring algorithms that also take into account groups of cells that can't yet be scored. Though I didn't implement different scoring methods, it would be interesting to see how those swaps differ from the ones that this program picks.
To get multiple graphs on a page, the x and y coordinates for each graph is dynamically generated. Based on the number of graphs to generate (10), the number of rows (5) and the number of columns (2), the graph of potential swaps is assigned a calculated coordinate to be at on the page.