Bulls and cows: Difference between revisions
Content added Content deleted
Line 7,475: | Line 7,475: | ||
VBS does'nt have a continue so i used the classic do loop inside do loop in the main program |
VBS does'nt have a continue so i used the classic do loop inside do loop in the main program |
||
<lang vb> |
<lang vb> |
||
dim p,c |
|||
randomize timer |
randomize timer |
||
fail=array("Wrong number of chars","Only figures 0 to 9 allowed","Two or more figures are the same") |
|||
p=dopuzzle() |
p=dopuzzle() |
||
wscript.echo "Bulls and Cows. Guess my 4 figure number!" |
wscript.echo "Bulls and Cows. Guess my 4 figure number!" |
||
Line 7,483: | Line 7,483: | ||
wscript.stdout.write vbcrlf & "your move ": s=trim(wscript.stdin.readline) |
wscript.stdout.write vbcrlf & "your move ": s=trim(wscript.stdin.readline) |
||
c=checkinput(s) |
c=checkinput(s) |
||
if not isarray (c) then wscript.stdout.write |
if not isarray (c) then wscript.stdout.write fail(c) :exit do |
||
bu=c(0) |
bu=c(0) |
||
wscript.stdout.write "bulls: " & c(0) & " | cows: " & c(1) |
wscript.stdout.write "bulls: " & c(0) & " | cows: " & c(1) |
||
Line 7,504: | Line 7,504: | ||
dim c(10) |
dim c(10) |
||
bu=0:co=0 |
bu=0:co=0 |
||
if len(s)<>4 then checkinput= |
if len(s)<>4 then checkinput=0:exit function |
||
for i=1 to 4 |
for i=1 to 4 |
||
b=mid(s,i,1) |
b=mid(s,i,1) |
||
if |
if instr("0123456789",b)=0 then checkinput=1 :exit function |
||
⚫ | |||
c(asc(b)-48)=1 |
c(asc(b)-48)=1 |
||
⚫ | |||
for j=1 to 4 |
for j=1 to 4 |
||
if asc(b)=asc(mid(p,j,1)) then |
if asc(b)=asc(mid(p,j,1)) then |
||
Line 7,518: | Line 7,518: | ||
checkinput=array(bu,co) |
checkinput=array(bu,co) |
||
end function |
end function |
||
</lang> |
</lang> |
||