Make your own free website on Tripod.com
Rules of CowBull

") ; parent.DisplayPane.document.write("I will assume a 4-digit number whichYou have to find out the number in the minimum ") ; parent.DisplayPane.document.write("possible attempts. For each digit that you find out you get :") ; parent.DisplayPane.document.write("Your target should be to find the number in less 6 chances.
") ; parent.DisplayPane.document.write("
Please send your comments to ") ; parent.DisplayPane.document.write("me through e-mail.
Thank you.

") ; parent.DisplayPane.document.write("") ; selectNumber() ; __inhelp__ = true ; } function notdigit(num) { if (num < '0' || num > '9') return 1 return 0 } function checknum(num, silent) { if (num.length != 4) { if (!silent) alert("Please enter exactly 4 digits.") return 1 } n1 = num.charAt(0) n2 = num.charAt(1) n3 = num.charAt(2) n4 = num.charAt(3) if (n1 == '0') { if (!silent) { alert("First digit cannot be ZERO.") document.cowbull.guess.value = "" } return 1 } if (notdigit(n1) || notdigit(n2) || notdigit(n3) || notdigit(n4)) { if (!silent) { alert("Please enter digits only.") document.cowbull.guess.value = "" } return 1 } if (n1 == n2 || n1 == n3 || n1 == n4 || n2 == n3 || n2 == n4 || n3 == n4) { if (!silent) { alert("Digits cannot be repeated.") document.cowbull.guess.value = "" } return 1 } return 0 } function tryCowBull() { if (!started) { alert("Please click Restart to start the game.") return } if (__gaveup__) { alert("No cheating ! You already gaveup !!\nPlease click Restart to start a new game.") return } yourNum = document.cowbull.guess.value if (checknum(yourNum, 0)) { document.cowbull.guess.focus() return } chance++ n1 = yourNum.substring(0, 1) n2 = yourNum.substring(1, 2) n3 = yourNum.substring(2, 3) n4 = yourNum.substring(3, 4) m1 = myNum.substring(0, 1) m2 = myNum.substring(1, 2) m3 = myNum.substring(2, 3) m4 = myNum.substring(3, 4) nCow = 0 nBull = 0 if ( n1 == m2 || n1 == m3 || n1 == m4) nCow++ if (n2 == m1 || n2 == m3 || n2 == m4) nCow++ if (n3 == m1 || n3 == m2 || n3 == m4) nCow++ if (n4 == m1 || n4 == m2 || n4 == m3) nCow++ if (n1 == m1) nBull++ if (n2 == m2) nBull++ if (n3 == m3) nBull++ if (n4 == m4) nBull++ if (nBull == 4) { showResult(chance, yourNum, nCow, nBull) return } showResult(chance, yourNum, nCow, nBull) document.cowbull.guess.focus() } function actualLength(str) { var buf = "" var i for (i = 0 ; i < str.length ; i++) if (str.charAt(i) != ' ') buf = buf + str.charAt(i) return buf.length } // End of JavaScript -->

Playing CowBull

Enter your guess in the text box below and click Try.
Your guess :