Jump to content

Welcome to Geeks to Go - Register now for FREE

Geeks To Go is a helpful hub, where thousands of volunteer geeks quickly serve friendly answers and support. Check out the forums and get free advice from the experts. Register now to gain access to all of our features, it's FREE and only takes one minute. Once registered and logged in, you will be able to create topics, post replies to existing threads, give reputation to your fellow members, get your own private messenger, post status updates, manage your profile and so much more.

Create Account How it Works
Photo

Turbo Pascal (Game Of Nim)


  • Please log in to reply

#1
Gabriel

Gabriel

    Member

  • Member
  • PipPip
  • 18 posts
Program nim;

uses wincrt;

var
player_turn :integer;
player :array[1..2] of string;
match_pile :array[1..5] of integer;
matches :integer;
pile_chosen :integer;
number_of_matches :integer;
total_matches :integer;


procedure C1_Input_turn_details;
begin
write('enter the pile number in which you wish to take from (1-5) ');
readln(pile_chosen);
write('enter the number of matches you wish to take (1-9) ');
readln(number_of_matches);
end;

procedure C2_Take_away_matches;
begin
match_pile[pile_chosen]:=match_pile[pile_chosen]-number_of_matches;
if total_matches = 0 then
A3_termination; 


end;

procedure C3_Display_piles;
begin
writeln('pile 1 = ',match_pile[1]);
writeln('pile 2 = ',match_pile[2]);
writeln('pile 3 = ',match_pile[3]);
writeln('pile 4 = ',match_pile[4]);
writeln('pile 5 = ',match_pile[5]);
end;

procedure B1_One_turn;
begin
if player_turn = 1 then
player_turn := 2
else
player_turn := 1;


repeat
C3_display_piles;
C1_input_turn_details;
C2_Take_away_matches;
until (player_turn = 4);
end;

procedure A1_initialisation;
begin
write('enter the name of player 1.. ');
readln(player[1]);
clrscr;
write('enter the name of player 2.. ');
readln(player[2]);
clrscr;
randomize;
match_pile[1]:=random(8)+1;
match_pile[2]:=random(8)+1;
match_pile[3]:=random(8)+1;
match_pile[4]:=random(8)+1;
match_pile[5]:=random(8)+1;
total_matches:=match_pile[1]+match_pile[2]+match_pile[3]+match_pile[4]+match_pile[5];
player_turn:=2;
end;

procedure A2_main_body;
begin
B1_one_turn;
end;

procedure A3_termination;
begin
end;

begin
A1_initialisation;
A2_main_body;
A3_termination;
end.

Assignment for college and my Lecurer has neglected the section of how to use Procedures correectly, having a little triuble correctly creating the procedures any help apreciated, if yoiu need any more information just ask thanks.

- Gabriel

p.s Just need pointers on what I may be doing wrong thanks, code is not 100% complete as of yet such as the terminatiomn procedure
  • 0

Advertisements


#2
Hai Mac

Hai Mac

    Member

  • Member
  • PipPipPip
  • 260 posts
Pascal is a top-down language. you cannot call a procedure declared later than where it is called.

Remedy: Move the A3_termination procedure before the C2_Take_away_matches;

Tell me if it worked :tazz:
  • 0

#3
Gabriel

Gabriel

    Member

  • Topic Starter
  • Member
  • PipPip
  • 18 posts

Pascal is a top-down language. you cannot call a procedure declared later than where it is called.

Remedy: Move the A3_termination procedure before the C2_Take_away_matches;

Tell me if it worked :tazz:


Thanks :) totally forgot about the Top-down.......

- Thanks
  • 0






Similar Topics

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

As Featured On:

Microsoft Yahoo BBC MSN PC Magazine Washington Post HP