Mailing List Archive: 49091 messages
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

[REBOL] Submitted, for your approval.

From: edanaii::cox::net at: 26-May-2002 15:15

Greetings all, Attached is a small game I created in my continuing effort to understand REBOL. It is another guessing game, slightly more sophisticated than the one I submitted previously. Please look it over and feel free to criticize, but do be gentle, as this is my second attempt at a REBOL program. ;) -- Sincerely, | We're Human Beings, with the blood of a million Ed Dana | savage years on our hands! But we can stop it! We Software Developer | can admit we're killers, but we're not going to 1Ghz Athlon Amiga | kill today. That's all it takes! Knowing that we're | not going to kill... Today! -- Star Trek. =========== http://members.cox.net/edanaii/Home/Default.html =========== -- Attached file included as plaintext by Listar -- -- File: Symbols.r REBOL [ Title: "Deduce the Symbols chosen by the computer." Date: 26-May-2002 Version: 1.0 To-do: { 1. Further use of Parameters. 2. Enhance based on further REBOL knowledge. 3. Better method of scoring. 4. GUI. 5. Variable Symbol and Guess sets. } File: %Symbols.r Author: "A guy with too much time on his hands." Gategory: "Game" Purpose: "An excersize in using and understanding REBOL." ] Symbols: Func[ ;=============================================================================== {This is a guessing game in which the player must guess five Symbols from among a set of eight. Each of the five are chosen randomly from the following set "~" "!" "@" "#" "$" "%" "&" "*" The game ends when the player correctly guesses all five symbols and their positions. The only clues offered are the number of symbols that match the computer's set and the number of symbols that are placed correctly inside the computers set. I.e. if the computer has chosen $#@#! and the player guesses *##~* the computer will respond with Matched: 1 Placed: 1. This is because the player's # matches the two chosen by the computer, one of which happens to be in the correct place. } ;=============================================================================== /Ask_Another {Asks player "another game?"} /Begin "Initializes the game." /Compare "Compares the player's choices to the computer's." /Deduce "Plays the game" /Indicate_Bad {Displays message "choices are bad."} /Indicate_Only_5 {Displays message "Only 5 symbols may be chosen."} /Indicate_Success {Displays message "You guessed them."} /New_Set "Creates a new set of choices" /Valid "Determines if the player's choices made are valid" ] [ If Ask_Another [ if (uppercase to-string first at (Ask "Would you like to play again? ") 1) = "N" [ Playing: False ] ] If Begin [ Symbol_Set: [ "~" "!" "@" "#" "$" "%" "&" "*" ] Random/seed Now ] If Deduce [ Symbols/Begin Playing: True While [ Playing ] [ Choices: Symbols/New_Set Turns: 0 While [ Choices <> Guess_Set: Ask "What is your guess? " ] [ Turns: Turns + 1 Either ( ( length? Guess_Set ) <> 5 ) [ Indicate_Only_5 ] [ Either Symbols/Valid [ Symbols/Compare ] [ Symbols/Indicate_Bad ] ] ] Symbols/Indicate_Success Symbols/Ask_Another ] ] If Compare [ Placed: 0 Matched: 0 For a 1 5 1 [ Either ( ( first at Guess_Set a ) = ( first at Choices a ) ) [ Placed: Placed + 1 ] [ If find Guess_Set to-string ( first at Choices a ) [ Matched: Matched + 1 ] ] ] Prin "Matched: " Prin Matched Prin " Placed: " Print Placed Print " " ] If Indicate_Bad [ Print "Not all the choices you've made are valid." Prin "Please make your choices from the following Symbols: " Print Symbol_Set ] If Indicate_Only_5 [ Print "Please enter only five choices" ] If Indicate_Success [ Print "That was it!" Prin "And you did it in only " Prin Turns Print " Turns." Print " " ] If New_Set [ Choices: "" Clear Choices loop 5 [ Insert Choices pick Symbol_Set random 8 ] Return Choices ] If Valid [ For a 1 5 1 [ Either ( find Symbol_Set to-string ( first at Guess_Set a ) ) [ Return True ] [ Return False ] ] ] ] Symbols/Deduce