CSE 231 Honors Project #1 Solved

40.00 $

Category:
Click Category Button to View Your Next Assignment | Homework

You'll get a download link with a: zip solution files instantly, after Payment

Securely Powered by: Secure Checkout

Description

5/5 - (2 votes)

Assignment Overview

Overview

Write a program that plays the game dots-and-boxes: https://en.wikipedia.org/wiki/Dots_and_Boxes and record some statistics about using a player who plays “randomly” i.e., a player who has no strategy except random play (to be described below). This version will focus on scoring play and getting RandomPlayer to play the game. The game should work for any dimensions (hint hint).

Play

The scoring is pretty well explained in the link above, but let’s review:

  • During a player’s turn, they must draw a line that connects two dots o They must play, they must draw a line, during their turn if a move is available.
  • Result of the line drawing:

o If drawing a line results in a box, that is a square is produced in the grid, then that player adds one to their score and can play again

  • The square is typically marked on the grid for that player o If no box is created, the turn ends and the next player plays.
  • Game ends when no more lines can be placed, that is all the lines have been played o Player with the most boxes wins

 

More details on play

The grid will be represented by ASCII characters on the terminal. A typical look below:

 

 

 

 

Some details:

  • If a player wins a box, it gets labeled. To keep things simple the two players are always named ‘A’ and ‘B’.
    • Who goes first is very important. You should flip a “dice” (generate a random number) and decide who goes first.
  • A move is a pair of integers. For example, as player A I made a move 4 5 (two space separated integers) which would draw that line. That’s a box, so when the grid is redrawn the square is filled in with A, and I get another turn using the updated grid. o You must prevent a user from redoing a move, so 2 6 would be illegal o Note an alternate naming of that same move would 5 4 and that would also be a legal move
  • Your program should:
    • Keep score and update it after every turn o Allow for extra moves when a box is drawn o Know when the game is over and report the results.

 

Data Structures

Come up with your own data structures. Things you will likely need:

  • A way to represent the grid o In that data structure, who drew what lines
  • A way to keep score

 

Functions or Classes

I don’t want to restrict you too much, but I do want readable code! You should be using functions or classes or you may not get credit. Some good functions (as suggestions):

 

  • draw_board: takes in your representation of moves and draws the board
  • check_for_box: takes in your representation of moves and determines, did that move just made make a box?
  • score: takes in score representation, perhaps using check_for_box, updating scores.

 

Random player

We are not going for automated strategy here nor are we going for human interaction. In the second round we are going to be making players that play the game well, but for now we are going to make a random player function called random_play

  • random_play: random_play could just keep picking until it finds a legal move but that is going to get to be painful. Instead, provide some information on available legal moves (state of the grid, something) and have it return a legal move. It selects its move using a random number generator, selecting from the available moves.

 

 

 

 

Main Program

You are going to use your random_play function to play dots-and-boxes. Your main program will operate in two modes:

  • single play: with two random_player players A and B, it is going to generate a fully detailed game, drawing grids, keeping score and showing in great detail the progress of the game.
  • multiple play: it will then play a lot of random games with two random_play players, however it will be reporting only statistics on how the two players did.

 

More detail

  • prompt for grid size
  • prompt for a random seed integer
  • prompt for a number of rounds the multi-player (shown below) will play
  • “flip a coin” to see who goes first and report it
  • your program will then play one round using two random_play players and report each individual play, stored in a file called “single_play.txt” to be created in the same directory as the project.
    • For each turn:
      • draw the grid
      • the score
      • whose move it is
      • what move was made
      • was that a box just made, did they go again
      • anything else that might be useful
    • it then will play the provided number of rounds using two random_play players and report statistics of the results to a file called

“multiple_play.txt”. The statistics to include are:

  • the number of rounds played o average score overall and for each player o the median score overall and for each player o the highest and lowest score achieved for each player o anything else you think might be a good idea

 

Deliverables

The deliverable for this assignment is the following files:

 

honors1.py – the source code for your Python program single_play.txt– the text file reporting each individual play  multiple_play.txt– the text file reporting the statistics of all the rounds Be sure to use the specified file names and to submit it via the Mimir system before the project deadline. No automatic tests will be posted in Mimir. The grading will be done manually.

 

Requirements

Your code must adhere to the entire Coding Standard.

Notes

  • because these are two random players the statistics on multiple hands will be revealing. What would you expect to happen?
  • you should be able to play thousands of games in multiple play to get some good stats.

o if it takes minutes to do that, you need to rethink it.

  • drawing a line might result in two boxes.
  • Honors1-yc7ds8.zip