This lab will have you and your lab partner implement an advanced game advisor for the game Ticket To Ride. In Part A, you finished implementing key graph algorithms that will prove essential to completing this week's lab. Many of the implementation details will be left to you, but this document will provide a general outline of game play.
To prevent confusion, here is some terminology used below:
A game of Ticket to Ride contains the following elements (I have bolded the elements you will have to represent in your game):
You will not be able to simulate the complete game from these requirements. Attending extensions for these elements is feasible, highly encouraged, but not required. Also, for claimed routes, you will only need to know what routes are no longer available for Player 1, not who actually owns them.
At a high level, your Ticket To Ride assistant will be able to:
This week's lab will emphasize creativity, design, and efficiency. We have provided you some sample code to help get started, but you should not feel locked into using them as is. Your rough grade break down for this week's lab is:
As usual, you can get the initial files for this lab by running update35. This will complete files from Part A. The new files are listed here.
A function for loading a map has been provided. You should use this as a template for loading tickets, which is similar except there is no weight provided. Each line is formatted as:
City A:City BNote that each vertex may contains spaces. Using the >> makes this tricky since it will only grab the string "City". On the other hand, getline grabs all inputs until it hits a new line character and puts into a string, e.g., "City A: City B". You can than parse this string as you see fit. See online documents or the given code for help
At a minimum, the user should be able to print a text as well as display a graphical representation of their board game. The map can either be the original game board or just the user's claimed routes. A possible implementation has been provided; feel free to modify this. Note that displaying the graph requires the GraphViz package. If you are working from home, comment these lines out or install the package.
Example:
Menu: (0) Exit (1) Print/display game board (2) Print/display my routes (3) Print available routes (4) Claim route for self (5) Claim route for opponent (6) Draw and select tickets (7) Print tickets and their status (8) Calculate current score Enter Choice: 1 Saint Louis: {Little Rock, Nashville} Little Rock: {Oklahoma City, Saint Louis, Nashville} Oklahoma City: {Little Rock} Nashville: {Little Rock, Saint Louis}Your map should look similar to the following:
Print in text all of the unclaimed routes (i.e., edges) on the original map. That is, if the user or one of the opponents has already claimed an edge, it should not be printed here. At a minimum, you should provide the cities at the ends of the edge as well as the number of cars needed to build the route (i.e., the edge length). This will help a user see what the possible plays are.
Example (note: the menu will be omitted from the remaining examples to save space, but should appear in your program):
MENU Enter choice: 3 Available Routes: ----------------- Saint Louis --- Little Rock : 2 Train Cars Saint Louis --- Nashville : 2 Train Cars Little Rock --- Oklahoma City : 2 Train Cars Little Rock --- Nashville : 3 Train Cars
Either the main player or one of their opponents can claim an available route. You should ask the player to indicate the cities connected by the route. If the (a) one of the cities is not in the map, (b) the main player owns the route, (c) an opponent owns the route, or (d) the route never existed, you should print a detailed error and return to the main menu (i.e., do not crash). You should also print the number of resources required (i.e., the edge weight) as well as the point value of the route (see "Calculating Scores").
Example:
Enter choice: 4 Enter city: St. Louis Error: That city does not exist. Returning to main menu. MENU Enter choice: 4 Enter city: Saint Louis Enter city: Oklahoma City Error: Route is not available. Returning to main menu. MENU Enter choice: 4 Enter city: Little Rock Enter city: Nashville You successfully claimed the route for 4 points. Please discard 3 train cards. MENU Enter choice: 5 Enter city: Nashville Enter city: Little Rock Error: Route is not available. Returning to main menu. MENU Enter choice: 2 Little Rock: {Nashville} Nashville: {Little Rock} MENU Enter choice: 5 Enter city: Little Rock Enter city: Saint Louis Your opponent successfully claimed the route for 2 points. MENU Enter choice: 3 Available Routes: ----------------- Saint Louis --- Nashville : 2 Train Cars Little Rock --- Oklahoma City : 2 Train Cars
This option will bring in many of your graph algorithms. Your method should:
Also, you should recall how to use randomness from earlier labs. It may be easier to shuffle the deck when reading the file and then simply add "discarded" tickets to the bottom of the pile. SEE BELOW FOR EXAMPLE.
For each ticket in the user's hand:
Given the user's claimed routes and destination tickets, calculate their current score. You should print out all claimed routes and their point value. A route's weight translates into points as follows:
$ ./ticketToRide inputs/smallBoard inputs/smallTickets Select a ticket to add to your hand: 1) Saint Louis to Oklahoma City for 4 points Achievable. Fewest routes needed (original board): 2. Fewest train cars needed (current board): 4 2) Nashville to Oklahoma City for 5 points Achievable. Fewest routes needed (original board): 2. Fewest train cars needed (current board): 5 3) Little Rock to Nashville for 3 points Achievable. Fewest routes needed (original board): 1. Fewest train cars needed (current board): 3 Enter choice or 0 to discard remaining tickets: 0 You are required to select at least 2 more tickets Select a ticket to add to your hand: 1) Saint Louis to Oklahoma City for 4 points Achievable. Fewest routes needed (original board): 2. Fewest train cars needed (current board): 4 2) Nashville to Oklahoma City for 5 points Achievable. Fewest routes needed (original board): 2. Fewest train cars needed (current board): 5 3) Little Rock to Nashville for 3 points Achievable. Fewest routes needed (original board): 1. Fewest train cars needed (current board): 3 Enter choice or 0 to discard remaining tickets: 3 Select a ticket to add to your hand: 1) Saint Louis to Oklahoma City for 4 points Achievable. Fewest routes needed (original board): 2. Fewest train cars needed (current board): 4 2) Nashville to Oklahoma City for 5 points Achievable. Fewest routes needed (original board): 2. Fewest train cars needed (current board): 5 Enter choice or 0 to discard remaining tickets: 1 Select a ticket to add to your hand: 1) Nashville to Oklahoma City for 5 points Achievable. Fewest routes needed (original board): 2. Fewest train cars needed (current board): 5 Enter choice or 0 to discard remaining tickets: 0 MENU Enter choice: 7 Your current destination tickets and their status: 0) Little Rock to Nashville for 3 points Ticket not punched, but path still exists You need at least 3 cars to complete the path 1) Saint Louis to Oklahoma City for 4 points Ticket not punched, but path still exists You need at least 4 cars to complete the path MENU Enter choice: 4 Enter city: Little Rock Enter city: Saint Louis You successfully claimed the route for 2 points. Please discard 2 train cards. MENU Enter choice: 7 Your current destination tickets and their status: 0) Little Rock to Nashville for 3 points Ticket not punched, but path still exists You need at least 2 cars to complete the path 1) Saint Louis to Oklahoma City for 4 points Ticket not punched, but path still exists You need at least 2 cars to complete the path MENU Enter choice: 5 Enter city: Saint Louis Enter city: Nashville Your opponent successfully claimed the route for 2 points. MENU Enter choice: 7 Your current destination tickets and their status: 0) Little Rock to Nashville for 3 points Ticket not punched, but path still exists You need at least 3 cars to complete the path 1) Saint Louis to Oklahoma City for 4 points Ticket not punched, but path still exists You need at least 2 cars to complete the path MENU Enter choice: 4 Enter city: Little Rock Enter city: Nashville You successfully claimed the route for 4 points. Please discard 3 train cards. MENU Enter choice: 7 Your current destination tickets and their status: 0) Little Rock to Nashville for 3 points Ticket punched 1) Saint Louis to Oklahoma City for 4 points Ticket not punched, but path still exists You need at least 2 cars to complete the path MENU Enter choice: 5 Enter city: Little Rock Enter city: Oklahoma City Your opponent successfully claimed the route for 2 points. MENU Enter choice: 7 Your current destination tickets and their status: 0) Little Rock to Nashville for 3 points Ticket punched 1) Saint Louis to Oklahoma City for 4 points It is impossible to punch this ticket MENU Enter choice: 6 Select a ticket to add to your hand: 1) Nashville to Oklahoma City for 5 points Ticket cannot be completed Enter choice or 0 to discard remaining tickets: 0 You are required to select at least 1 more tickets Select a ticket to add to your hand: 1) Nashville to Oklahoma City for 5 points Ticket cannot be completed Enter choice or 0 to discard remaining tickets: 1 MENU Enter choice: 8 Your current score breakdown: ----------------------------- Routes: Saint Louis -- Little Rock: +2 points Little Rock -- Nashville: +3 points Destination tickets: Little Rock --- Nashville: +3 points Saint Louis --- Oklahoma City: -4 points Nashville --- Oklahoma City: -5 points Total: -1 points MENU Enter choice: 0
Once you are satisfied with your program, hand it in by typing handin35 at the unix prompt.
You may run handin35 as many times as you like, and only the most recent submission will be recorded. This is useful if you realize after handing in some programs that you'd like to make a few more changes to them.