lab05
by typing:
mkdir lab05Change to this directory by typing:
cd lab05
The standard exercises for this lab are to write functions which together form a program which allow a user to play Farnarkle.
The challenge exercises are to write a program which itself plays Farnarkle.
Farnarkle is thought to have been invented in Iceland during the Little Ice Age. It is played with numbered tiles, originally made from sections of Narwhal tusks. Each tile is inscribed with a single positive integer. Traditionally the integers on the tiles are from the range 1..8 (the number 8 is significant in Norse mythology).
In modern Farnarkle variants the integers on the tiles may be from the range 1..10, 1..12, or another range.
Farnarkle starts with with the Arkle Master choosing a hidden sequence of tiles. Traditionally this sequence is of 4 tiles, but there are modern variants with 5 or 8 tiles in this sequence.
The player then attempts to guess the hidden sequence in a series of turns. Each turn they lay out a sequence of tiles. The Arkle Master then gives them information about how well their sequence of tiles matches the hidden sequence of tiles.
This information is given as two integers: the number of Arkles and the number of Farnarkles.
A tile is counted as an Farnarkle if it has the same number as the tile in the same position in the hidden sequence.
A tile is counted as an Arkle if it has the same number as a tile in another position in the hidden sequence.
A tile that is counted as a Farnarkle is not counted in an Arkle.
A tile can only be counted once in an Arkle.
The scoring of this example Farnarkle game should clarify the definition of Farnarkles and Arkles.
Hidden Sequence | 4 2 7 7 | ||
---|---|---|---|
Turn | Guess | Farnarkles | Arkles |
1 | 1 2 3 4 | 1 | 1 |
2 | 3 5 5 8 | 0 | 0 |
3 | 4 3 2 1 | 1 | 1 |
4 | 7 7 7 7 | 2 | 0 |
5 | 7 6 5 4 | 0 | 2 |
6 | 7 7 4 2 | 0 | 4 |
7 | 4 2 7 7 | 4 | 0 |
Note: the game is complete when the player guess the hidden sequence.
Here is the code to start the lab.
Read this file carefully. You must use this file to start the assignment.
It contains a main function which will allow you to test the functions you write in the lab.
Do not change the main function, or the other functions in the file.
Add your code to this file in the indicated places.
Do not change other parts of the file.
Note you need to submit farnarkle.c for each exercise to obtain the marks for that exercises.
Only the function for that exercise will be automarked.
// return number of farnarkles
int count_farnarkles(int tiles1[N_TILES], int tiles2[N_TILES]) {
int n_farnarkles = 0;
int i = 0;
while (i < N_TILES) {
if (tiles1[i] == tiles2[i]) {
n_farnarkles = n_farnarkles + 1;
}
i = i + 1;
}
return n_farnarkles;
}
count_farnarkles should given two tile sequences, return the number of farnarkles.
Note: it doesn't matter which sequence is the hidden sequence and which is the guess.
farnarkle.c contains a main function which will let you test count_farnarkles
For example:
dcc farnarkle.c -o farnarkle ./farnarkle Enter 0 to call count_farnarkles() Enter 1 to call count_arkles() Enter 2 to call play_farnarkle() Enter 3 to call test_ai_farnarkle_player() Call which function: 0 Enter tile sequence 1: 1 2 3 4 Enter tile sequence 2: 2 1 3 8 count_farnarkles returned 1 for Sequence 1: 1 2 3 4 Sequence 2: 2 1 3 8 ./farnarkle Enter 0 to call count_farnarkles() Enter 1 to call count_arkles() Enter 2 to call play_farnarkle() Enter 3 to call test_ai_farnarkle_player() Call which function: 0 Enter tile sequence 1: 5 5 6 5 Enter tile sequence 2: 6 5 5 5 count_farnarkles returned 2 for Sequence 1: 5 5 6 5 Sequence 2: 6 5 5 5
When you think your program is working you can use autotest
to run some simple automated tests:
1511 autotest count_farnarkles
give cs1511 wk05_count_farnarkles farnarkle.cNote, even though this is a pair exercise, you both must run give from your own account before Sunday 8 April 23:59:59 to obtain the marks for this lab exercise.
INTERNAL ERROR MISSING FILE: "activities/count_arkles/farnarkle.c"
count_arkles should given two tile sequences, return the number of arkles.
Note: it doesn't matter which sequence is the hidden sequence and which is the guess.
farnarkle.c contains a main function which will let you test count_arkles
For example:
dcc farnarkle.c -o farnarkle ./farnarkle Enter 0 to call count_farnarkles() Enter 1 to call count_arkles() Enter 2 to call play_farnarkle() Enter 3 to call test_ai_farnarkle_player() Call which function: 1 Enter tile sequence 1: 1 2 3 4 Enter tile sequence 2: 2 1 3 2 count_arkles returned 2 for Sequence 1: 1 2 3 4 Sequence 2: 2 1 3 2 ./farnarkle Enter 0 to call count_farnarkles() Enter 1 to call count_arkles() Enter 2 to call play_farnarkle() Enter 3 to call test_ai_farnarkle_player() Call which function: 1 Enter tile sequence 1: 5 8 5 5 Enter tile sequence 2: 8 5 8 8 count_arkles returned 2 for Sequence 1: 5 8 5 5 Sequence 2: 8 5 8 8
When you think your program is working you can use autotest
to run some simple automated tests:
1511 autotest count_arkles
give cs1511 wk05_count_arkles farnarkle.cNote, even though this is a pair exercise, you both must run give from your own account before Sunday 8 April 23:59:59 to obtain the marks for this lab exercise.
INTERNAL ERROR MISSING FILE: "activities/play_farnarkle/farnarkle.c"
play_farnarkle should given a hidden tile sequences, reads guesses from a human player,
printing the number of farnarkles and arkles for each guess, until the human player guesses the sequence.
Use read_tiles to read the guesses.
farnarkle.c contains a main function which will let you test play_farnarkle
For example:
./farnarkle Enter 0 to call count_farnarkles() Enter 1 to call count_arkles() Enter 2 to call play_farnarkle() Enter 3 to call test_ai_farnarkle_player() Call which function: 2 Enter guess for turn 1: 1 5 7 8 0 farnarkles, 1 arkles Enter guess for turn 2: 2 3 4 6 3 farnarkles, 0 arkles Enter guess for turn 3: 2 3 4 7 2 farnarkles, 0 arkles Enter guess for turn 4: 2 3 8 6 3 farnarkles, 0 arkles Enter guess for turn 5: 2 3 1 6 4 farnarkles, 0 arkles You win
When you think your program is working you can use autotest
to run some simple automated tests:
1511 autotest play_farnarkle
give cs1511 wk05_play_farnarkle farnarkle.cNote, even though this is a pair exercise, you both must run give from your own account before Sunday 8 April 23:59:59 to obtain the marks for this lab exercise.
Do not use global or static variables to store information between calls tofarnarkle_ai .
farnarkle.c contains a main function which will let you test farnarkle_ai
For example:
dcc farnarkle.c -o farnarkle ./farnarkle Enter 0 to call count_farnarkles() Enter 1 to call count_arkles() Enter 2 to call play_farnarkle() Enter 3 to call test_ai_farnarkle_player() Call which function: 3 Enter hidden tiles: 4 5 3 5 Turn 1: farnarkle AI guess is: 1 1 1 1 = 0 farnarkles, 0 arkles Turn 2: farnarkle AI guess is: 2 2 2 2 = 0 farnarkles, 0 arkles Turn 3: farnarkle AI guess is: 3 3 3 3 = 1 farnarkles, 0 arkles Turn 4: farnarkle AI guess is: 4 4 4 3 = 1 farnarkles, 1 arkles Turn 5: farnarkle AI guess is: 5 4 3 5 = 2 farnarkles, 2 arkles Turn 6: farnarkle AI guess is: 4 5 3 5 = 4 farnarkles, 0 arkles Farnarkle AI took 6 turns to guess the tiles.
A farnarkle player tournament will be announced on the class web page at the end of the week.
N_TILES
and MAX_TILE
will vary between tournament rounds.
N_TILES
will always be in the range 2..8 (inclusive) and MAX_TILE
will always be in the range 4..16 (inclusive)
The challenge mark will be based on how well your player performs in this tournament.
Can you make your farnarkle player optimal - make it take, on average, the smallest number of turns possible to guess a code?
Can you prove that your farnarkle player is optimal?
If you can not construct a proof and/or an optimal player, construct a logical argument as to why your player is close to optimal.
The autotest for farnarkle_ai give yours function previous guesses, with farnarkle and arkle counts such that only there is only possible guess consistent with them.
When you think your program is working you can use autotest
to run some simple automated tests:
1511 autotest farnarkle_ai
give cs1511 wk05_farnarkle_ai farnarkle.cYou must run give before Sunday 8 April 23:59:59 to obtain the marks for this lab exercise. Note, this is an individual exercise, the work you submit with give must be entirely your own.
You can run give multiple times. Only your last submission will be marked.
Don't submit any exercises you haven't attempted.
If you are working at home, you may find it more convenient to upload your work via give's web interface.
Remember you have until Sunday 8 April 23:59:59 to submit your work.
Automarking will be run several days after the submission deadline for the test. When complete you can view automarking here and you can view the the resulting mark via give's web interface
You can read more about lab assessment here