Search the Community
Showing results for tags 'spock lizard'.
-
This is a function I came up with to determine the outcome of selecting Paper, Scissors or Rock. See below for more details. Function and Example: (Classic game) Example() Func Example() Local $sComputer, $sOutcome = '', $sUser = '' For $i = 0 To 2 For $j = 0 To 2 Switch _RockPaperScissors($i, $j, $sUser, $sComputer) Case -1 ; Draw $sOutcome = 'Draw' Case 0 ; Lose $sOutcome = 'Lost' Case Else ; Win $sOutcome = 'Won' EndSwitch ConsoleWrite('The user selected ' & $sUser & ' and the PC chose ' & $sComputer & ', the outcome was: ' & $sOutcome & @CRLF) Next Next EndFunc ;==>Example ; #FUNCTION# ==================================================================================================================== ; Name ..........: _RockPaperScissors ; Description ...: Determine the outcome between the classic game of 'Paper, Scissors or Rock?' ; Syntax ........: _RockPaperScissors($iUserChoice, $iComputerChoice, Byref $sUserChoice, Byref $sComputerChoice) ; Parameters ....: $iUserChoice - An integer value of the item for the user (see remarks.) ; $iComputerChoice - An integer value of the item for the computer (see remarks.) ; $sUserChoice - [in/out] A variable to store the string representation of the user's choice. ; $sComputerChoice - [in/out] A variable to store the string representation of the computer's choice. ; Return values .: |-1 - Draw (both choices resulted in a draw.) ; |0 - Lose (the user's choice lost.) ; |1 - Win (the user's choice won.) ; Author ........: guinness ; Modified ......: Malkey - Idea for ComputerChoice + 1. ; Remarks .......: |0 - Rock ; |1 - Paper ; |2 - Scissors ; Example .......: Yes ; =============================================================================================================================== Func _RockPaperScissors($iUserChoice, $iComputerChoice, ByRef $sUserChoice, ByRef $sComputerChoice) Local $aChoice[3][4] = [['Rock', -1, 0, 1],['Paper', 1, -1, 0],['Scissors', 0, 1, -1]] If $iUserChoice = Default Then $iUserChoice = 0 If $iComputerChoice = Default Then $iComputerChoice = Random(0, 2, 1) $sUserChoice = $aChoice[$iUserChoice][0] $sComputerChoice = $aChoice[$iComputerChoice][0] Return $aChoice[$iUserChoice][$iComputerChoice + 1] EndFunc ;==>_RockPaperScissorsFunction and Example: (New variation with Spock and Lizard) Example() Func Example() Local $sComputer, $sOutcome = '', $sUser = '' For $i = 0 To 4 For $j = 0 To 4 Switch _RockPaperScissorsLizardSpock($i, $j, $sUser, $sComputer) Case -1 ; Draw $sOutcome = 'Draw' Case 0 ; Lose $sOutcome = 'Lost' Case Else ; Win $sOutcome = 'Won' EndSwitch ConsoleWrite('The user selected ' & $sUser & ' and the PC chose ' & $sComputer & ', the outcome was: ' & $sOutcome & @CRLF) Next Next EndFunc ;==>Example ; #FUNCTION# ==================================================================================================================== ; Name ..........: _RockPaperScissorsLizardSpock ; Description ...: Determine the outcome between the unique game of 'Rock, Paper, Scissors, Lizard or Spock?' ; Syntax ........: _RockPaperScissorsLizardSpock($iUserChoice, $iComputerChoice, Byref $sUserChoice, Byref $sComputerChoice) ; Parameters ....: $iUserChoice - An integer value of the item for the user (see remarks.) ; $iComputerChoice - An integer value of the item for the computer (see remarks.) ; $sUserChoice - [in/out] A variable to store the string representation of the user's choice. ; $sComputerChoice - [in/out] A variable to store the string representation of the computer's choice. ; Return values .: |-1 - Draw (both choices resulted in a draw.) ; |0 - Lose (the user's choice lost.) ; |1 - Win (the user's choice won.) ; Author ........: guinness ; Modified ......: Malkey - Idea for ComputerChoice + 1. ; Remarks .......: |0 - Rock ; |1 - Paper ; |2 - Scissors ; |3 - Lizard ; |4 - Spock ; Example .......: Yes ; =============================================================================================================================== Func _RockPaperScissorsLizardSpock($iUserChoice, $iComputerChoice, ByRef $sUserChoice, ByRef $sComputerChoice) Local $aChoice[5][6] = [['Rock', -1, 0, 1, 1, 0],['Paper', 1, -1, 0, 0, 1],['Scissors', 0, 1, -1, 1, 0],['Lizard', 0, 1, 0, -1, 1],['Spock', 1, 0, 1, 0, -1]] If $iUserChoice = Default Then $iUserChoice = 0 If $iComputerChoice = Default Then $iComputerChoice = Random(0, 4, 1) $sUserChoice = $aChoice[$iUserChoice][0] $sComputerChoice = $aChoice[$iComputerChoice][0] Return $aChoice[$iUserChoice][$iComputerChoice + 1] EndFunc ;==>_RockPaperScissorsLizardSpock