Get 20
Author |
Message |
cool dude
|
Posted: Sun Mar 26, 2006 8:17 pm Post subject: Get 20 |
|
|
i was playing a game with my sister a while back and decided to program it in turing just for fun because i was bored. u can play this game with 2 people but i made it against the computer. my AI is really good and almost unbeatable! if u r good at math and logic u will figure out how to beat it and if u cant then just post and i'll tell u how.
RULES
it is very simple but may sound complicated!!!
basically u start off by choosing either 1 or 2.
then the computer chooses a number that is 1 or 2 greater than your number
then u have to choose a number that is 1 or 2 greater than the computers number and so on...
the object of this game is to land on the number 20 and then u win!
P.S. i know it is terrible coding but it took me about 15 min and i didn't want to think about making it sufficient and stuff. i'm sure i and others can make this game in less than 60 lines of code. also this was one of my first programs done in turing so i didn't know arrays back then otherwise it would have been much better!!!
P.P.S since i said i made this just for fun i didn't want to error proof so please don't comment on any error proofing
Description: |
|
Download |
Filename: |
number game.t |
Filesize: |
3.5 KB |
Downloaded: |
154 Time(s) |
|
|
|
|
|
|
Sponsor Sponsor
|
|
|
MysticVegeta
|
Posted: Mon Mar 27, 2006 11:36 am Post subject: (No subject) |
|
|
The goal of the game is that the player should choose 17, so that whatever moves the computer makes you win, and this cycle repeats, same with 17, the goal now becomes for you to choose 14 so whatever the computer chooses you will able to land on 17 and win. The cycle repeats. Didnt take longer than a minute to figure it out =\ pretty straightforward.
Cycle for the player to choose to win it:
2
5
8
11
14
17
20
Dont worry anything the computer chooses you win
|
|
|
|
|
|
MysticVegeta
|
Posted: Mon Mar 27, 2006 12:07 pm Post subject: (No subject) |
|
|
code: | var choose : array 1 .. 7 of int := init (2, 5, 8, 11, 14, 17, 20)
var num : int
var mainAns : int := 0
fcn getGreater (n : int) : int
var ans : int
for x : 1 .. 7
if (n + 1 = choose (x)) or (n + 2 = choose (x)) then
ans := choose (x)
result ans
elsif n = choose (x) then
ans := n + Rand.Int (1, 2)
result ans
end if
end for
end getGreater
loop
cls
put "Enter a number > ", mainAns, " + and increment of 1 or 2: " ..
get num
if num > mainAns and num <= mainAns + 2 then
if num = 20 then
put "YOU WIN"
exit
end if
%AI
mainAns := getGreater (num)
put "The computer chose: ", mainAns
delay (1000)
if mainAns = 20 then
put "YOU LOSE"
exit
end if
else
cls
put "Invalid Input"
delay (1000)
end if
end loop
|
The same effective AI in 40 lines.
|
|
|
|
|
|
cool dude
|
Posted: Mon Mar 27, 2006 5:19 pm Post subject: (No subject) |
|
|
lol ya your code is 2 times less but as i said it was one of my earlier programs i made and i didn't know arrays back then so i couldn't really do that.
anyways your right its not too hard to figure the numbers out but suprisingly if u play this game with most people u will win every time because people these days don't have logic. lol.
|
|
|
|
|
|
MysticVegeta
|
Posted: Mon Mar 27, 2006 6:00 pm Post subject: (No subject) |
|
|
Heh, I remember solving this type of question (ofcourse harder) on the Grade 10 Cayley contest a month or 2 back. Ticked me off cause it involved 4 players and variable increments each time, my head hurt so much after solving it though, damn, I will see if I can find it
|
|
|
|
|
|
|
|