Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Any tips? I'm stuck on my game
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
barney




PostPosted: Wed Jun 07, 2006 5:56 pm   Post subject: Any tips? I'm stuck on my game

As you might have seen from my other post about Rand.Int, I need to make a Mastermind game with a flower theme. But I'm stuck when it comes to the hints...

code:
const BP := "Black Peg \n"
const WP := "White Peg \n"

var guess : string
var answer : string
var ans1 := intstr (Rand.Int (1, 5))
var ans2 := intstr (Rand.Int (1, 5))
var ans3 := intstr (Rand.Int (1, 5))
var ans4 := intstr (Rand.Int (1, 5))
var continue_char : string (1)
var count : int

answer := ans1 + ans2 + ans3 + ans4
put answer         %Testing purpose

color (103)
put "\t\t\t\tFLORAL MASTERMIND"
put "\nEnter your answer using the following coding scheme: \n\t* Dandelion - 1 \n\t* Daisy - 2 \n\t* Lily - 3 \n\t* Rose - 4 \n\t* Tulip - 5"
put "\nEnter any key to continue."
getch (continue_char)
put "\nEnter your answer: " ..
get guess

if (guess (1) = answer (1)) and (guess (2) = answer (2)) and (guess (3) = answer (3)) and (guess (4) = answer (4)) then
    put repeat (BP, 4)
elsif (guess (1) = answer (1)) and (guess (2) = answer (2)) and (guess (3) = answer (3)) and (guess (4) not= answer (4)) then
    put repeat (BP, 3)
elsif (guess (1) = answer (1)) and (guess (2) = answer (2)) and (guess (3) not= answer (3)) and (guess (4) not= answer (4)) then
    put repeat (BP, 2)
elsif (guess (1) = answer (1)) and (guess (2) not= answer (2)) and (guess (3) not= answer (3)) and (guess (4) not= answer (4)) then
    put BP
elsif (guess (1) not= answer (1)) and (guess (2) not= answer (2)) and (guess (3) not= answer (3)) and (guess (4) = answer (4)) then
    put WP
elsif (guess (1) not= answer (1)) and (guess (2) not= answer (2)) and (guess (3) = answer (3)) and (guess (4) = answer (4)) then
    put repeat (WP, 2)
elsif (guess (1) not= answer (1)) and (guess (2) = answer (2)) and (guess (3) = answer (3)) and (guess (4) = answer (4)) then
    put repeat (WP, 3)
%elsif (guess (1) not= answer (1)) and (guess (2) = answer (2)) and (guess (3) = answer (3)) and (guess (4) = answer (4)) then
%    put repeat (WP, 4)
end if


Any tips on how to do my hints?

ps. I know most of you will want to offer some advice on arrays, but I'm not allowed to use any. Confused
Sponsor
Sponsor
Sponsor
sponsor
HellblazerX




PostPosted: Wed Jun 07, 2006 8:55 pm   Post subject: (No subject)

I'm still not getting why you have those subscripts, and what I mean by that is this:
code:
guess (1)

Those should only be used if you're using arrays, which you're obviously not, and if you're using string manipulation, which from the looks of your program, you're not either. So why do you have them? Because all they do is make it so your program doesn't work. Btw, why aren't you allowed to use arrays?
devilwhat




PostPosted: Wed Jun 07, 2006 9:42 pm   Post subject: (No subject)

do you have your whole code...if so id like to take a look at it...i too am trying to create this game...but i used arrays...
barney




PostPosted: Wed Jun 07, 2006 9:45 pm   Post subject: (No subject)

OK, I'm using those subscripts because I'm comparing the user's answer against mine, character by character. I know that's going to take ages for me to finish, but I can't think of any other simpler way to do it! Embarassed And my teacher is crazy, don't ask why she doesn't want us to use arrays Rolling Eyes I think she thinks we can't handle it lol.
Guest




PostPosted: Wed Jun 07, 2006 10:03 pm   Post subject: (No subject)

HellblazerX wrote:
I'm still not getting why you have those subscripts, and what I mean by that is this:
code:
guess (1)

Those should only be used if you're using arrays, which you're obviously not, and if you're using string manipulation, which from the looks of your program, you're not either. So why do you have them? Because all they do is make it so your program doesn't work. Btw, why aren't you allowed to use arrays?


He isn't doing half the things you are saying because he is new to Turing. I was the same way too =)
barney




PostPosted: Wed Jun 07, 2006 10:20 pm   Post subject: (No subject)

vahnx wrote:
barney wrote:
OK, I'm using those subscripts because I'm comparing the user's answer against mine, character by character. I know that's going to take ages for me to finish, but I can't think of any other simpler way to do it! Embarassed And my teacher is crazy, don't ask why she doesn't want us to use arrays Rolling Eyes I think she thinks we can't handle it lol.


You.... Have a female programming teacher??? I know this is off topic, but is she hot??? All us nerds know that coming across a female programming teacher is rare...


Excuse me, I feel the need to use capital letters.

I'M A FEMALE TOO! Barney is just a nickname, it's not my real name!
And my teacher is pregnant at the moment, so that pretty much explains why she's making crazy decisions...lol. OK, back to topic please!
Dan




PostPosted: Wed Jun 07, 2006 11:31 pm   Post subject: (No subject)

Deleted a bunch of posts above this.

This is NOT myspace or some lame dating site. If you have personal message about or to some one send them threw the PM system, e-mail, msn, ect.

vahnx wrote:

You.... Have a female programming teacher??? I know this is off topic, but is she hot??? All us nerds know that coming across a female programming teacher is rare...


Please do not push unture and hurtfull sterotpyes, it just degrages us all. It may be true that the magority of peoleop in computer science are male but this dose not mean us progamers drop everything when we see a girl and yell "OMG A GIRL WTF DO I DO" and start runing around in circles.
In fact most peoleop i know in computer science are noraml peoleop with nomral realtionships and even girl firends.

Also out of 3 of the computer science teachers i had in high school 2 where female and in unviersity the prof that thougth about 4 of my progaming cores was also female. And futher more, with the cores i toke at collage about 1/2 of the insutrchers where female. This is hardly a rare thing epstaly in high school where computer science teachers need no offical training in computer science to teach it.
Computer Science Canada Help with programming in C, C++, Java, PHP, Ruby, Turing, VB and more!
devilwhat




PostPosted: Thu Jun 08, 2006 9:10 am   Post subject: (No subject)

exactly...i know a lot of female programmers....but other than that...if anyone could help me programming this code it would be helpful
Sponsor
Sponsor
Sponsor
sponsor
barney




PostPosted: Thu Jun 08, 2006 4:32 pm   Post subject: (No subject)

Ok, could we get back to topic please? Can I get any tips? I'm so lost! Is there an easier way to do the hint part of my game without using arrays or continuous if statements?
barney




PostPosted: Thu Jun 08, 2006 5:35 pm   Post subject: (No subject)

OK, so I tried fiddling around with a new attempt at this hint stuff. But there's something wrong with it, and I can't exactly figure it out. =( Can anyone help please? Everytime i type in the right answer, it gives me one black peg, and three white pegs. It's not supposed to do that. It's supposed to give me four black pegs... Confused

code:
put "\t\t\t\tFLORAL MASTERMIND"
put "\nEnter your answer using the following coding scheme: \n\t* Dandelion - 1 \n\t* Daisy - 2 \n\t* Lily - 3 \n\t* Rose - 4 \n\t* Tulip - 5"
put "\nEnter any key to continue."
getch (continue_char)
put "\nEnter your answer: " ..
get guess

%Guess(1)
if guess (1) = answer (1) then
    put BP
elsif guess (1) = answer (2) then
    put WP
elsif guess (1) = answer (3) then
    put WP
elsif guess (1) = answer (4) then
    put WP
else
    put "Error: invalid choice, please try again."
end if

%Guess 2
if guess (2) = answer (1) then
    put BP
elsif guess (2) = answer (2) then
    put WP
elsif guess (2) = answer (3) then
    put WP
elsif guess (2) = answer (4) then
    put WP
else
    put "Error: invalid choice, please try again."
end if

%Guess 3
if guess (3) = answer (1) then
    put BP
elsif guess (3) = answer (2) then
    put WP
elsif guess (3) = answer (3) then
    put WP
elsif guess (3) = answer (4) then
    put WP
else
    put "Error: invalid choice, please try again."
end if

%Guess 4
if guess (4) = answer (1) then
    put BP
elsif guess (4) = answer (2) then
    put WP
elsif guess (4) = answer (3) then
    put WP
elsif guess (4) = answer (4) then
    put WP
else
    put "Error: invalid choice, please try again."
end if
TheOneTrueGod




PostPosted: Thu Jun 08, 2006 5:56 pm   Post subject: (No subject)

Why not nested for loops?

code:

%Assuming that they entered a string that was >= length of 4
for i : 1..4
   for j : 1..4
      if guess(i) = answer(i) then
         put BP
      end if
   end for
end for


You'd also need a loop around the "Enter your guess" and the checking for their guess part.

Theres a couple problems with the method I gave you above, such as if answer(1) = "1" and they guessed "1111" then it'll tell you that you got it right, but if you use some flags, then you can probably work around it.

Though, you should probably know something of the mastermind game...
lets assume answer = "ABCD"
lets assume guess = "DCBA"

the program should tell them they have 4 correct, but they are all in the wrong place.

if guess = "DCCD" then it should tell them they have 2 wrong, and 2 in the right place.


Another way around it

The best way that I can see would be to put this all into a function, and have it return a string (4).

"2222" would indicate they got everything 100% correct
"2211" would indicate they got 2 in the right place, and 2 in the wrong place
"0020" would indicate they got the third one in the right place, and the rest were entirely wrong.

Of course, you can use whatever characters you want to represent whatever, but the point remains, put it into a function. It'll make your life a lot easier.

[Turing Walkthrough] has some info on functions.
barney




PostPosted: Thu Jun 08, 2006 7:49 pm   Post subject: (No subject)

OK....um I checked out the Turing Walkthrough about Functions, and it really did not make any sense to me whatsoever. Care to explain what you meant a bit more? Confused
Omnipotence




PostPosted: Sun Jun 11, 2006 10:29 pm   Post subject: (No subject)

Alright barney, I'm pretty sure Ms. Cairns (Teacher in question) wouldnt be too happy with you posting stuff on this forum for others to help with. Let alone your source code.

The whole point of using substring isn't for you to inefficiently manually code your way through it all over again. It is used for the exact purpose of LOOPS. Functions aren't really necessary. As for generating your hint, using loops, just start comparing position x to position x to figure stuff out.

so if two things were in the same position and they were the same, you would know that its correct.

P.S For anyone planning to submit to this forum, please don't give out any code to help them out. Its in the wishes of the teacher in question and itd be no good for the development of any programmer in the class.
Martin




PostPosted: Mon Jun 12, 2006 3:04 am   Post subject: (No subject)

barney wrote:
OK....um I checked out the Turing Walkthrough about Functions, and it really did not make any sense to me whatsoever. Care to explain what you meant a bit more? Confused


A function is like a function in math. For example, suppose that you had to add the numbers from 1 to n. Your code might look like this:

code:
var n : int
n := 10
var sum : int
sum := 0
for i : 1 .. n
  sum := sum + i
end for
put sum


Now, let's say that you need to do this a lot. Instead of copying and pasting that code over and over, you can write a function, which would look like this:

code:

function sum_to_n(n : int) : int
  var sum : int
  sum := 0
  for i : 1 .. n
    sum := sum + i
  end for
  return sum
end sum_to_n

put sum_to_n(10)
put sum_to_n(5)
...
devilwhat




PostPosted: Mon Jun 12, 2006 12:47 pm   Post subject: (No subject)

P.S For anyone planning to submit to this forum, please don't give out any code to help them out. Its in the wishes of the teacher in question and itd be no good for the development of any programmer in the class.[/quote]

Can anyone help me out. I don't have this teacher and am trying to make a similar game so that I can play it on my own time offline.
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 15 Posts ]
Jump to:   


Style:  
Search: