Oxen & Cows Re:Mastermind - A game of logic
"valery_vi" <[email protected]>
| Newsgroups | gmane.comp.windows.autoit.user |
|---|---|
| Message-ID | <[email protected]> |
I decided to write this game. The rules of it was described early and
code of it is follows:
;==================================================
; Russian Game: 'Oxen & Cows'
; Author of AutoIt script: Valery Ivanov
; Date: 28 March 2007
;
#include <GUIConstants.au3>
Global $PlayerNumber, $Result, $Number, $Place, $Oxen = 0, $Cows = 0
$hWnd = GUICreate("Oxen & Cows Valery Ivanov", 400, 450)
$LabelOfPlayerNumber = GUICtrlCreateLabel("Type integer number from
1000 to 9999:", 10, 10, 380, 21)
$PlayerNumber = GUICtrlCreateInput("", 10, 30, 380, 21)
$LabelOfResult = GUICtrlCreateLabel("Checks:", 10, 60, 380, 21)
$Result = GUICtrlCreateEdit("*** New Game ***" & @CRLF, 10, 90, 380,
280, $ES_READONLY)
$Check = GUICtrlCreateButton('CheckIt', 150, 390, 100, 30)
NextNumber()
Random(0,9.999)
GUISetState()
; Start the main loop
While 1
$Msg = GUIGetMsg()
Switch $Msg
Case $GUI_EVENT_CLOSE
Exit
Case $Result
WinSetTitle($hWnd, "", GUICtrlRead($Result))
Case $Check
CheckIt(GUICtrlRead($PlayerNumber))
EndSwitch
WEnd
;Get new number
func NextNumber()
local $Digit
$Number = Random(0,9,1)
$Digit = Random(0,9,1)
for $i = 1 to 3
While StringInStr($Number, $Digit)
; Msgbox(0,'','$Digit = ' & $Digit & ' $Number = ' & $Number)
$Digit = Random(0,9,1)
Wend
$Number &= $Digit
next
; Msgbox(0, 'NextNumber', 'Number = ' & $Number)
endfunc
;Check user's number
func CheckIt($Player)
$PArray = StringRegExp($Player,'([0-9])([0-9])([0-9])([0-9])',3)
if @Error or StringLen($Player) > 4 then
Msgbox(0, 'Error', 'Type integer number from 1000 to 9999')
GUICtrlSetData($PlayerNumber,'')
return
endif
$NArray = StringSplit($Number,'')
for $i = 0 to 3
if $PArray[$i]=$NArray[$i+1] then
$Oxen += 1
else
if StringInStr($Player,$NArray[$i+1]) then $Cows +=1
endif
next
$Line = GUICtrlRead($Result)
$Line &= $Player & ' ==> '
If $Cows then
$Line &= $Cows & ' Cows'
if $Oxen then $Line &= ', '
endif
If $Oxen then $Line &= $Oxen & ' Oxen'
If Not $Cows and Not $Oxen then $Line &= ' No animals!'
$Line &= @CRLF
GUICtrlSetData($Result,$Line)
GUICtrlSetData($PlayerNumber,'')
if Number($Oxen) = 4 then
$Line = GUICtrlRead($Result)
$Line &= ' You found my number. It is ' & $Player & @CRLF
$Line &= @CRLF & '*** New Game ***' & @CRLF
GUICtrlSetData($Result,$Line)
NextNumber()
endif
$Oxen = 0
$Cows = 0
endfunc
Time of coding was 2 hours, though.
Enjoy,
Valery
--- In [email protected], "valery_vi" <shehrer1@...> wrote:
>
> About names in Russian game 'Oxen & Cows':
> 1. Cow is your white square and Ox is black one.
> 2. Ox is animal which always stay on place but cow can run away for
> some reasons. This is like the nature of these animals, I think.
> :-)
>
> BTW. Recently I've been thinking about invalid spelling of word
> Moscow. Russian call this city like Mosqua : [Mos-`kva].
> Why English-speaking world deformed this word Moscua into Moscow?
>
> It hasn't cows at all.
> :-)
>
> Valery
>
> --- In [email protected], "valery_vi" <shehrer1@> wrote:
> >
> > Hi,
> >
> > Piano Man wrote:
> > http://www.autoitscript.com/forum/index.php?showtopic=43343
> > "..When I first showed this to my colleagues I was surprised by
how
> > many people hadn't played it, so I won't be surprised if most of
> you
> > haven't played it. "
> >
> > This is colorized variant of game known in Russia as 'Oxens &
> Cows'.
> > Russian game 'Oxens & Cows' is the following:
> > 1. Leader has integer number. 4-digits. No doubles allowed!
> > 2. Player tests his variants. Integer number from 4-digits.
> > 3. If digit exists in leader's number then it is Cow
> > 4. If digit exists in leader's number and is placed on the valid
> > place then it is Oxen.
> > 5. Answer or result of test (your check result) will be for
example:
> >
> > 2 Cows and 1 Ox
> > or
> > Just 3 Cows...
> > :-)
> >
> > Thus, your expert's version (4 rows) with 9 colors (numbers of
> > digits - 0..9) will be colorized Russian logical game 'Oxens &
> Cows'.
> > I remember that 6-7 questions is typical result for advanced
player.
> > My result for your game (Beginner) is 4 rows.
> >
> > Valery
> >
>