Main

Assignment 1

1. Course intro

Access the course webpage, Wiki, and the Piazza course page. There is nothing you need to hand in for this problem.

2. Accounts and Unix intro

2a.

If you don't already have an ix/ix-dev account, request it at https://systems.cs.uoregon.edu/wiki/index.php?n=Help.Account . For instructions on using ssh to access ix and ix-dev, see https://systems.cs.uoregon.edu/wiki/index.php?n=Help.AppsSSH . (nothing to hand in for this problem).

2b.

Complete Chapters 1 and 2 in Unix Tutorial for Beginners (nothing to hand in for this problem).

3. Using Bitbucket

Set up your Bitbucket git repository for this course. We will be using Bitbucket for all coding assignments and the project.

  • Create a Bitbucket account (if you don't already have one).
  • Create a new git repository named uoregon-cis330 by following these instructions. Make sure to make the repository private (step 5 in the instructions, also see an example repository creation form screenshot).
  • In your repository's settings, give brnorris03 (Prof. Norris's bitbucket username) write access to your new repository (see detailed Instructions). Also, give the GTFs write access, their Bitbucket usernames are chrismisa (Chris Misa) and aamimeur (Amnay Amineur).
  • Important:

If you haven't done so already, fill out this short form, including your Bitbucket username: https://goo.gl/forms/Nd6pMXw6H5aJHfnf2

  • At the Unix shell command line (on ix-dev or another Unix machine where you will be working), clone your uoregon-cis330 git repository, e.g. by using a command similar to:
git clone https://username@bitbucket.org/username/uoregon-cis330.git
  • Create a new assignment1 directory in your uoregon-cis330 git repository. The directory name must be exactly assignment1, all lowercase, no spaces. Create a file in that directory (it doesn't matter what is in it). Then, add the directory to your repository (refer to the Git documentation for details). For example:
touch assignment1/tempfile
git add assignment1
git commit -m "directory for the first assignment" assignment1
git push
(The touch command simply creates an empty file if it doesn't already exist or updates its timestamp if it does exist.)

4. Compiling and running C programs

4.a Warm up with small programs

  • In the assignment1 directory of your uoregon-cis330 git repository, create two files, first.c and avg.c with the code from the examples in Chapter 1 of ThinkingInC. Compile the files with gcc and run them. Verify that they produce the expected output. Check in the source files into the repository (you will need to use git add, git commit, and git push).

4.b A simple game

  • In the assignment1 directory of your uoregon-cis330 git repository, download and edit the file sticks.c file to implement the game of sticks where one of the players is the user and the other is the computer. In the game of sticks there is a heap of sticks on a board. On their turn, each player picks up 1 to 3 sticks. The one who has to pick the final stick will be the loser. You are free to implement any reasonable strategy for the computer's turns.

Add, commit, and push sticks.c to your git repository. Compile and test your implementation. The following shows example executions.

$ ./a.out
Welcome to the game of sticks!
How many sticks are there on the table initially (10-100)? 12

There are 12 sticks on the board.
Player 1: How many sticks do you take (1-3)? 3

There are 9 sticks on the board.
Computer selects 2.

There are 7 sticks on the board.
Player 1: How many sticks do you take (1-3)? 3

There are 4 sticks on the board.
Computer selects 3.

There are 1 sticks on the board.
Player 1: How many sticks do you take (1-3)? 1
You lose!

$ ./a.out
Welcome to the game of sticks!
How many sticks are there on the table initially (10-100)? 10

There are 10 sticks on the board.
Player 1: How many sticks do you take (1-3)? 2

There are 8 sticks on the board.
Computer selects 1.

There are 7 sticks on the board.
Player 1: How many sticks do you take (1-3)? 3

There are 4 sticks on the board.
Computer selects 1.

There are 3 sticks on the board.
Player 1: How many sticks do you take (1-3)? 2

There are 1 sticks on the board.
Computer selects 1.
You win!
You can also run a sample solution on ix with the command ~norris/public/cis330/assignment1/sticks.

You can also run a sample solution on ix.cs.uoregon.edu with the command ~norris/public/cis330/assignment1/sticks. You have to first ssh to ix-dev before you can copy and paste the command to run it.

Green Marinee theme adapted by David Gilbert, powered by PmWiki