• Best of luck to the class of 2024 for their HSC exams. You got this!
    Let us know your thoughts on the HSC exams here
  • YOU can help the next generation of students in the community!
    Share your trial papers and notes on our Notes & Resources page
MedVision ad

Algorithm Help (1 Viewer)

gress

Member
Joined
Feb 4, 2004
Messages
51
Location
randw
BEING MAINPROGRAM

INITIALISATION
set ReqPts to 9
set each players points to 0
END INITIALISATION

toss and decide server
REPEAT
server serves the ball
REPEAT
play the rally
UNTIL rally is won
IF server wins rally THEN
increment server's points by 1
ELSE
swap player status
ENDIF
UNTIL a player has won ReqPts
declare winner
END MAINPROGRAM

BEING SUBPROG toss and decide server
toss a coin
IF heads THEN
player 1 is the server
player 2 is the recieiver
ELSE
player 2 is the server
player 1 is the receiver
ENDIF
END SUBPROG toss and decide server

I'd indent if I knew how but..
This is in my year 12 sdd notes, theres no way I wrote this myself so [not really my style] so credit goes to whoever I copied it off or wherever I got it from. (internet maybe?)

so yeah.. hope that helps
 

SamD

Member
Joined
Jul 21, 2002
Messages
256
Gender
Male
HSC
N/A
1. What's the point of the INITIALISE Variables line, its irrelevant as this is what the next two lines do.
2. What does Coin Toss mean, presumably determines who serves. You need to detail this somehow.
3. What does Play game mean when it's within a loop. Seems to me this inside Repeat is unnecessary, you could have just said Play Point or similar.
4. Your technique for adding points to the server's score is a mess. How is the value in ServerScore shoved back into the relevant Playerscore? I'd suggest using an array with two elements, one for each player.
5. More detail needed to explain Switch Player Status, no idea how this is done at present. If you use an array then you just change 0 to 1 or 1 to 0 to do this.

Marks wise I'd say you'd get about 60%

HTH
Sam
 
Last edited:

sikeveo

back after sem2
Joined
Feb 22, 2004
Messages
1,794
Location
North Shore
Gender
Male
HSC
2005
hmm, im completely lost at what was said in the above post, anyone care to lead by example? I know how to detail the toss coin one, but im lost with how to add the points a better way and using an array. And how would u change the player status using an array?
thanks guys

ps. im in yr11 so still 60%?
 
Last edited:

fatmuscle

Active Member
Joined
Jul 6, 2002
Messages
3,707
Location
Hornsby
Gender
Male
HSC
2001
BEGIN Main
>>Set Player1score and Player2score to 0
>>Set ServerScore to 0

>>Coin Toss
>>WHILE Player1score < 9 AND Player2score < 9
>>>>Server serves ball
>>>>REPEAT
>>>>>>IF Server is Player1 THEN
>>>>>>>>ServerScore = Player1score
>>>>>>ELSE
>>>>>>>>ServerScore = Player2 score
>>>>>>ENDIF
>>>>>>Play game
>>>>UNTIL Rally is won by player
>>>>IF Server wins game THEN
>>>>>>ServerScore = ServerScore + 1
>>>>ELSE
>>>>>>Switch player status
>>>>ENDIF
>>ENDWHILE
>>Declare winner
>>Give trophy
END Main


Begin Sub Coin Toss
>>Player 1 Choose Side
>>Player 2 Choose Side
>>Toss Coin
>>IF Player 1s side is face up THEN
>>>>Player 1 is the server
>>>>Player 2 is the receiver
>>ELSE
>>>>Player 2 is the server
>>>>Player 1 is the receiver
>>END IF
END Sub Coin Toss
 

SamD

Member
Joined
Jul 21, 2002
Messages
256
Gender
Male
HSC
N/A
Originally posted by SamD
2. What does Coin Toss mean, presumably determines who serves. You need to detail this somehow.
If you use an array then Player1Score and Player2Score could become PlayerScore(Server) where Server is either 0 or 1. Now you can toss the coin and if Head then Server=0 else Server=1.

3. What does Play game mean when it's within a loop. Seems to me this inside Repeat is unnecessary, you could have just said Play Point or similar.
The question asks to "describe how to score a ball game", so its unecessary to have this repeat loop at all. Furthermore I can't see how your IF statement within this loop works. Just trash the whole loop and replace with Play Rally.

4. Your technique for adding points to the server's score is a mess. How is the value in ServerScore shoved back into the relevant Playerscore? I'd suggest using an array with two elements, one for each player.
If you use an array as above then after each rally your IF becomes: IF Server wins rally THEN add 1 to PlayerScore(Server) ELSE Swap Server.

5. More detail needed to explain Switch Player Status, no idea how this is done at present. If you use an array then you just change 0 to 1 or 1 to 0 to do this.
If using an array then swapping server really means changing the value of the variable Server from 0 to 1 (or viceversa). Could just be Server=(Server+1) MOD 2.

HTH
Sam
 

sikeveo

back after sem2
Joined
Feb 22, 2004
Messages
1,794
Location
North Shore
Gender
Male
HSC
2005
is this right?


BEGIN Main
> Define PlayerScore(Server) as array
Set PlayerScore(Server) to 0

>>Coin Toss
>>WHILE PlayerScore(Server) < 9
>>>>Server serves ball
>>>>>>Play point
>>>>IF Server wins point THEN
>>>>>>PlayerScore(Server) = PlayerScore(Server) + 1
>>>>ELSE
>>>>>> Server=(Server+1) MOD 2
>>>>ENDIF
>>ENDWHILE
>>PlayerScore(Server) = Winner
END Main


Begin Sub Coin Toss
>>Toss Coin
>>IF Heads THEN
>>>>Server = 0
>>ELSE
>>>>Server = 1
>>END IF
END Sub Coin Toss
 

SamD

Member
Joined
Jul 21, 2002
Messages
256
Gender
Male
HSC
N/A
Heaps better! Your in Band 5 now!!

To get into Band 6 consider the following:

1. You don't need to define data structures in algorithms, so trash that line.
2. Your PlayerScore(Server)=0 is vague. You should initialise both PlayerScores explicitly. ie. PlayerScore(0)=0 and PlayerScore(1)=0.
3. PlayerScore(Server)=Winner is wrong. The winner is the current Server. So something like Winner is Server, or to map 0,1 to player 1,2 you could have Winner is Server+1.
4. Finally, fix up your indenting... or is it just how it looks in this post. I doubt you'd lose marks for this but it makes it easier for the marker.

HTH
Sam
 

Winston

Active Member
Joined
Aug 30, 2002
Messages
6,128
Gender
Undisclosed
HSC
2003
Yeah it looks much better, and i think you missed some minor thing

Coin Toss, must be underlined, as you are calling a sub-routine.
 

fatmuscle

Active Member
Joined
Jul 6, 2002
Messages
3,707
Location
Hornsby
Gender
Male
HSC
2001
Originally posted by sikeveo
hey thanks guyz :)
you should not have deleted your original post.

it's valuable for other students who are learning or struggling with algorithms.

while you are learning and being corrected, other students are learning too. Do not be ashamed of getting stuff wrong.
 

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Top