Assignment 4 – Legal move checking
1 Revising
2 Design, Build and Test

Assignment 4 – Legal move checking

Due Wednesday 4/20 5:00pm for the testing deliverables and Friday 4/22 11:59pm for the code deliverables

1 Revising

Take a look back at the code you wrote for assignment 3.

If your data design is exactly the same as the unmarshalled JSON, revisit it and revise it. The way the rows of homes are represented is especially terrible for working with that portion of the player state.

If your code doesn’t consist of at least two separate libraries (one with the data defintions and helper functions and a separate one for marshaling/unmarshaling JSON values), then refactor your code from last week to separate those parts out.

Finally, did you see anything during the codewalks that would help you improve your code? If so, make those changes. Expect to discuss that in your codewalk if you are selected.

2 Design, Build and Test

Building on the design of your data structure for the game state and the player state, this week you must implement a function that accepts a game state, an initial player state and a subsequent player state. The function should return a boolean that indicates if the two player states correspond to before and after states of a legal move.

For example, if the player starts in the initial state (as was shown in assignment 3), and this is the game state:

{"city-plans":[{"criteria":[1,1,1,1,1,1],"position":1,"score1":8,"score2":4},{"criteria":[1,1,1,6],"position":2,"score1":11,"score2":6},{"criteria":[1,2,6],"position":3,"score1":12,"score2":7}],"city-plans-won":[false,false,false],"construction-cards":[[1,"surveyor"],[2,"landscaper"],[3,"pool"]],"effects":["agent","bis","temp"]}

then it would be legal for the player to put a 1 on the first house in the row and mark off an agent, as shown here:

image

and this is the corresponding JSON for the resulting player state:

{"agents":[0,0,0,1,0,0],"city-plan-score":["blank","blank","blank"],"refusals":0,"streets":[{"homes":[1,false,[false,"blank",false],[false,"blank",false],[false,"blank",false],[false,"blank",false],[false,"blank",false],[false,"blank",false],[false,"blank",false],[false,"blank",false],[false,"blank",false]],"parks":0,"pools":[false,false,false]},{"homes":["blank",false,[false,"blank",false],[false,"blank",false],[false,"blank",false],[false,"blank",false],[false,"blank",false],[false,"blank",false],[false,"blank",false],[false,"blank",false],[false,"blank",false],[false,"blank",false]],"parks":0,"pools":[false,false,false]},{"homes":["blank",false,[false,"blank",false],[false,"blank",false],[false,"blank",false],[false,"blank",false],[false,"blank",false],[false,"blank",false],[false,"blank",false],[false,"blank",false],[false,"blank",false],[false,"blank",false],[false,"blank",false]],"parks":0,"pools":[false,false,false]}],"temps":0}

With these as input, your function should return true. If, however, the after state were this one, where the player has put a 2 house number but still marked off the same agent:

image

where this is the corresponding JSON:

{"agents":[0,0,0,1,0,0],"city-plan-score":["blank","blank","blank"],"refusals":0,"streets":[{"homes":[2,false,[false,"blank",false],[false,"blank",false],[false,"blank",false],[false,"blank",false],[false,"blank",false],[false,"blank",false],[false,"blank",false],[false,"blank",false],[false,"blank",false]],"parks":0,"pools":[false,false,false]},{"homes":["blank",false,[false,"blank",false],[false,"blank",false],[false,"blank",false],[false,"blank",false],[false,"blank",false],[false,"blank",false],[false,"blank",false],[false,"blank",false],[false,"blank",false],[false,"blank",false]],"parks":0,"pools":[false,false,false]},{"homes":["blank",false,[false,"blank",false],[false,"blank",false],[false,"blank",false],[false,"blank",false],[false,"blank",false],[false,"blank",false],[false,"blank",false],[false,"blank",false],[false,"blank",false],[false,"blank",false],[false,"blank",false]],"parks":0,"pools":[false,false,false]}],"temps":0}

then your function should return false.

Testing Deliverables: In your team’s GitHub repository, create a directory “Deliverables/4/4.1/” and put at least ten input files that each have a single JSON list containing three JSON objects: the game state, followed by the initial player state, and then the final player state. Create ten output files that each have either true or false, depending if the move represented by the corresponding input file contains a valid move or not.

Note that both of the player state JSON objects must be legal according to assignment 3, so this already rules out some illegal moves as test cases. There are still many ways to move illegally, however!

You will receive up to twenty points for your tests, two points for each valid pair of input and output files that do not duplicate existing tests.

Code Deliverables: In your team’s GitHub repository, create a directory “Deliverables/4/4.1/” and deposit there a Makefile for your test driver. It should accept a single JSON object on stdin that is a list containing the game state, followed by the initial player state, and then the final player state. It should print either true or false to indicate if the move was legal or not.

You will receive up to 50 points for your code.