![]() |
Faculty of Engineering and Information Technology (FEIT)
Department of Computer Science
|
COMP2310 Assignment 1Deadline: 23:57 Tuesday 4th September 2007
Late Penalty: Submission DetailsYou are required to submit a single compressed tar file from the student system (or partch) using the following command:submit comp2310 Ass1 comp2310_ass1.tar.gzThe following illustrates how (on partch) you should produce the above file: partch> pwd /students/u9507815/comp2310_ass1 partch> ls game_advanced game_basic generic_queue_pack.ads game_advanced.adb game_basic.adb generic_queue_pack.ali game_advanced.adb~ game_basic.ali generic_queue_pack.o game_advanced.ali game_basic.o write-up.txt game_advanced.o generic_queue_pack.adb partch> rm *.o *.ali game_advanced game_basic (i.e. remove the rubbish!) partch> ls game_advanced.adb generic_queue_pack.adb game_basic.adb generic_queue_pack.ads write-up.txt partch> cd .. partch> tar -zcvf comp2310_ass1.tgz comp2310_ass1/ partch> submit comp2310 Ass1 comp2310_ass1.tgz comp2310_ass1.tgz submittedThe submitted will will then be processed as follows
partch> pwd
/students/comp2310/submission/u9507815
partch> ls
comp2310_ass1.tgz
partch> tar -zxf comp2310_ass1.tgz
partch> cd comp2310_ass1
partch> ls
game_advanced.adb generic_queue_pack.adb
game_basic.adb generic_queue_pack.ads
write-up.txt
partch> gnatmake game_basic
gcc-4.1 -c game_basic.adb
gcc-4.1 -c generic_queue_pack.adb
gnatbind -x game_basic.ali
gnatlink game_basic.ali
partch> gnatmake game_advanced
gcc-4.1 -c game_advanced.adb
gnatbind -x game_advanced.ali
gnatlink game_advanced.ali
partch> game_basic
STUPID Player 3 has won the game after picking up 13 cards
Winning hand: Jack Spades, Jack Hearts, Jack Diamonds, Jack Clubs, 9 Spades
(comment - we will run your code a few times)
partch> game_advanced -n 6 -m 2
accepted options:
[-n {number of players: positive}] -> default: 4
[-m {number of smart players: positive}] -> default: 1
number of players 6
number of smart players 2
SMART Player 5 is winner after picking up 13 cards
Winning hand: Jack Spades, Jack Hearts, Jack Diamonds, Jack Clubs
SMART Player 6 is second after picking up 17 cards
Winning hand: Ace Spades, Ace Hearts, Ace Diamonds, Ace Clubs
STUPID Player 3 is third after picking up 16 cards
Winning hand: King Spades, King Hearts, King Diamonds, King Clubs
Game stopped as only 3 players left
Shall we play another round?
(comment: we will run the advanced code a few times with different input)
partch> cat write-up.txt
This is where I give a brief write-up of what I have done and how I have
done it. This should be in plain text.
Some notes:
In this assignment you will develop an Ada program to play a simple card game.
The Basic Game There are 4 players. From a standard deck of cards you select 24 cards consisting of all four suites for six different kinds, eg the Ace, King, Queen, Jack, 10 and 9 of Clubs, Diamonds, Hearts and Spades. The players are seated around a table, and between each player is a (possibly empty) pile of cards. The game begins with each player being given four cards and each pile containing two cards. The initial assignment of cards to players or piles is random (i.e. the cards have been shuffled).Once the game is started, each player can pick one card at a time from their right-hand pile (assuming it is not empty) and discard one card at a time to the left-hand pile. They can not pick up and discard a card at the same time. Each player can only hold 5 cards in their hand at any time. All players can play simultaneously, so there is no specific order of play (i.e. there is no concept of a turn). The game ends when one player has four cards of the same kind (e.g. four kings). There can only be one winner.
Implementation: Basic Game (worth 80% of the assignment mark)Implement the above game using Ada. Your program should require no input.Your program should implement two types of players:
SMART(or)STUPID Player X has won the game after picking up N cards Winning hand: Ace Spades, Ace Hearts, Ace Diamonds, Ace Clubs, King SpadesThe program should produce no other output. The program should ensure that only one player can ever win the game and that termination takes place as soon as practically possible after any player has been identified as the winner. Your program should also terminate if any player has picked up more than 100 cards. In this situation your program should printout a message of the following form:
SMART(or)STUPID Player X has picked up more than 100 cards
Play aborted!
Your program should never printout both the "won" and "abort" message.The following code demonstrates how to generate random integers within some range.
with Ada.Numerics.Discrete_Random;
with Ada.Text_IO; use Ada.Text_IO;
with Ada.Integer_Text_IO; use Ada.Integer_Text_IO;
with GNAT.Command_Line; use GNAT.Command_Line;
procedure Game_Basic is
subtype Random_Guess is Integer range 0..4;
package My_Random is new
Ada.Numerics.Discrete_Random(Random_Guess);
use My_Random;
My_Number: Random_Guess;
Number_Generator: My_Random.Generator;
begin
Reset(Number_Generator);
for I in 1..10 loop
My_Number := Random(Number_Generator);
New_Line; Put ("Random Number "); Put (My_Number, 5);
end loop;
end Game_Basic;
Implementation: Advanced Game (worth 20% of the assignment mark)Only attempt this part of the assignment if you have completed the above. This will be a separate code submission.Modify your code from above (but keep the above version) as follows
with Ada.Text_IO; use Ada.Text_IO;
with Ada.Integer_Text_IO; use Ada.Integer_Text_IO;
with GNAT.Command_Line; use GNAT.Command_Line;
procedure Game_Advanced is
No_Of_Players : Positive := 4;
No_Of_Smart : Positive := 1;
Options_Ok : Boolean := True;
Option : Character;
procedure Print_Options is
begin
New_Line; Put ("accepted options:");
New_Line; Put (" [-n {number of players: positive}] -> default:"); Put (No_Of_Players, 5);
New_Line; Put (" [-m {number of smart players: positive}] -> default:"); Put (No_Of_Smart, 5);
New_Line;
end Print_Options;
begin
Print_Options;
Initialize_Option_Scan;
loop
begin
Option := Getopt ("n: m:");
case Option is
when ASCII.NUL => exit;
when 'n' => No_Of_Players := Positive'Value (Parameter);
when 'm' => No_Of_Smart := Positive'Value (Parameter);
when others => raise Program_Error;
end case;
exception
when others =>
New_Line; Put ("---> Error in option -");
Put (Option); New_Line;
Options_Ok := False;
end;
end loop;
New_Line; Put ("number of players "); Put (No_Of_Players);
New_Line; Put ("number of smart players"); Put (No_Of_Smart);
end Game_Advanced;
|
|
Please direct all enquiries to: Alistair.Rendell@anu.edu.au Page authorised by: Head of Department, DCS |
| The Australian National University — CRICOS Provider Number 00120C |