SlideShare a Scribd company logo
Tic Tac Toe in PHP';
for($i=0; $i<$size; $i++) {
for($j=0; $j<$size; $j++) {
$count++;
$retVal.='';
}
$retVal.='
';
}
$retVal.='';
echo $retVal;
}
function genBox2($size,$arr) {
global
$bsize,$playerToken,$myToken,$gameOver,$winArr,$rowArr,$colArr,$digArr,$vals,$s1,$s2,$s
3,$s4,$s5,$s6,$s7,$s8,$s9;
$count=0;
$retVal='';
for($i=0; $i<$size; $i++) {
for($j=0; $j<$size; $j++) {
$count++;
$retVal.='';
}
$retVal.='
';
}
$retVal.='';
echo $retVal;
}
function isEmpty($who) {
if($who=="")
return 1;
else
return 0;
}
function move($bsize,$arr) {
global
$bsize,$playerToken,$myToken,$gameOver,$winArr,$rowArr,$colArr,$digArr,$vals,$s1,$s2,$s
3,$s4,$s5,$s6,$s7,$s8,$s9;
$count=0;
$maxCount=0;
$pos=0;
$retVal=0;
# Build Row Array
for($i=0; $i<$bsize; $i++) {
$maxCount=0;
$fullCounter=0;
for($j=0; $j<$bsize; $j++) {
$count++;
$who=$arr[$count-1];
if($who==$playerToken) {
$maxCount++;
$fullCounter++;
}
if($who==$myToken)
$fullCounter++;
}
$rowArr[$i]=$maxCount;
if($fullCounter==$bsize)
$rowArr[$i]=-1;
}
# Building Column Array
for($i=0; $i<$bsize; $i++) {
$count=$i+1;
$maxCount=0;
$fullCounter=0;
for($j=0; $j<$bsize; $j++) {
$who=$arr[$count-1];
if($who==$playerToken) {
$maxCount++;
$fullCounter++;
}
if($who==$myToken)
$fullCounter++;
$count+=$bsize;
}
$colArr[$i]=$maxCount;
if($fullCounter==$bsize)
$colArr[$i]=-1;
}
# Building Diagonal Array
for($i=0; $i<2; $i++) {
if($i==0)
$count=$i+1;
else
$count=$bsize;
$maxCount=0;
$fullCounter=0;
for($j=0; $j<$bsize; $j++) {
$who=$arr[$count-1];
if($who==$playerToken) {
$maxCount++;
$fullCounter++;
}
if($who==$myToken)
$fullCounter++;
if($i==0)
$count+=$bsize+1;
else
$count+=$bsize-1;
}
$digArr[$i]=$maxCount;
if($fullCounter==$bsize)
$digArr[$i]=-1;
}
# Finding Max Values
$maxRow=myMax(0,$bsize,"row",$rowArr);
$maxCol=myMax(0,$bsize,"col",$colArr);
$maxDig=myMax(0,$bsize,"dig",$digArr);
$maxArrs[0]=myMax(1,$bsize,"row",$rowArr);
$maxArrs[1]=myMax(1,$bsize,"col",$colArr);
$maxArrs[2]=myMax(1,$bsize,"dig",$digArr);
//$maxArrs=array(max(1,$bsize,"row",$rowArr),max(1,$bsize,"col",$colArr),max(1,$bsize,"
dig",$digArr));
if(myMax(0,$bsize,"x",$maxArrs)==0)
$pos=$bsize*($maxRow+1)-$bsize;
if(myMax(0,$bsize,"x",$maxArrs)==1)
$pos=$maxCol;
if(myMax(0,$bsize,"x",$maxArrs)==2)
if($maxDig==0)
$pos=$maxDig;
else
$pos=$bsize-1;
$retFlag=0;
for($y=0; $y<$bsize; $y++) {
if(!$retFlag) {
if($arr[$pos]=="") {
$retVal=$pos;
$retFlag=1;
}
if(myMax(0,$bsize,"x",$maxArrs)==0)
$pos++;
if(myMax(0,$bsize,"x",$maxArrs)==1)
$pos+=$bsize;
if(myMax(0,$bsize,"x",$maxArrs)==2)
if($maxDig==0)
$pos+=$bsize+1;
else
$pos+=$bsize-1;
}
}
return $retVal;
}
function myMax($what,$bsize,$type,$arr) {
global
$bsize,$playerToken,$myToken,$gameOver,$winArr,$rowArr,$colArr,$digArr,$vals,$s1,$s2,$s
3,$s4,$s5,$s6,$s7,$s8,$s9;
$max=-1;
$maxIndex=-1;
if($type!="dig") {
for($i=0; $i<$bsize; $i++) {
if($arr[$i]>$max) {
$max=$arr[$i];
$maxIndex=$i;
}
}
}
if($type=="dig") {
for($i=0; $i<2; $i++) {
if($arr[$i]>$max) {
$max=$arr[$i];
$maxIndex=$i;
}
}
}
if($what==0)
return $maxIndex;
else
return $max;
}
function playerWin() {
global
$bsize,$playerToken,$myToken,$gameOver,$winArr,$rowArr,$colArr,$digArr,$vals,$s1,$s2,$s
3,$s4,$s5,$s6,$s7,$s8,$s9;
$who=$playerToken;
if(($s1==$who && $s2==$s1 && $s3==$s1) || ($s4==$who && $s5==$s4 &&
$s6==$s4)||($s7==$who && $s8==$s7 && $s9==$s7) ||($s1==$who && $s4==$s1 &&
$s7==$s1) ||($s2==$who && $s5==$s2 && $s8==$s2) ||($s3==$who && $s6==$s3 &&
$s9==$s3) ||($s1==$who && $s5==$s1 && $s9==$s1) ||($s3==$who && $s5==$s3 &&
$s7==$s3))
return 1;
else
return 0;
}
function iWin() {
global
$bsize,$playerToken,$myToken,$gameOver,$winArr,$rowArr,$colArr,$digArr,$vals,$s1,$s2,$s
3,$s4,$s5,$s6,$s7,$s8,$s9;
$who=$myToken;
if(($s1==$who && $s2==$s1 && $s3==$s1) || ($s4==$who && $s5==$s4 &&
$s6==$s4)||($s7==$who && $s8==$s7 && $s9==$s7) ||($s1==$who && $s4==$s1 &&
$s7==$s1) ||($s2==$who && $s5==$s2 && $s8==$s2) ||($s3==$who && $s6==$s3 &&
$s9==$s3) ||($s1==$who && $s5==$s1 && $s9==$s1) ||($s3==$who && $s5==$s3 &&
$s7==$s3))
return 1;
else
return 0;
}
function whereWinComp() {
global
$bsize,$playerToken,$myToken,$gameOver,$winArr,$rowArr,$colArr,$digArr,$vals,$s1,$s2,$s
3,$s4,$s5,$s6,$s7,$s8,$s9;
$who=$myToken;
if(($s1==$who && $s2==$s1 && $s3==$s1))
$winArr=array('s1','s2','s3');
if(($s4==$who && $s5==$s4 && $s6==$s4))
$winArr=array('s4','s5','s6');
if(($s7==$who && $s8==$s7 && $s9==$s7))
$winArr=array('s7','s8','s9');
if(($s1==$who && $s4==$s1 && $s7==$s1))
$winArr=array('s1','s4','s7');
if(($s2==$who && $s5==$s2 && $s8==$s2))
$winArr=array('s2','s5','s8');
if(($s3==$who && $s6==$s3 && $s9==$s3))
$winArr=array('s3','s6','s9');
if(($s1==$who && $s5==$s1 && $s9==$s1))
$winArr=array('s1','s5','s9');
if(($s3==$who && $s5==$s3 && $s7==$s3))
$winArr=array('s3','s5','s7');
}
function whereWinPlayer() {
global
$bsize,$playerToken,$myToken,$gameOver,$winArr,$rowArr,$colArr,$digArr,$vals,$s1,$s2,$s
3,$s4,$s5,$s6,$s7,$s8,$s9;
$who=$playerToken;
if(($s1==$who && $s2==$s1 && $s3==$s1))
$winArr=array('s1','s2','s3');
if(($s4==$who && $s5==$s4 && $s6==$s4))
$winArr=array('s4','s5','s6');
if(($s7==$who && $s8==$s7 && $s9==$s7))
$winArr=array('s7','s8','s9');
if(($s1==$who && $s4==$s1 && $s7==$s1))
$winArr=array('s1','s4','s7');
if(($s2==$who && $s5==$s2 && $s8==$s2))
$winArr=array('s2','s5','s8');
if(($s3==$who && $s6==$s3 && $s9==$s3))
$winArr=array('s3','s6','s9');
if(($s1==$who && $s5==$s1 && $s9==$s1))
$winArr=array('s1','s5','s9');
if(($s3==$who && $s5==$s3 && $s7==$s3))
$winArr=array('s3','s5','s7');
}
function draw() {
global
$bsize,$playerToken,$myToken,$gameOver,$winArr,$rowArr,$colArr,$digArr,$vals,$s1,$s2,$s
3,$s4,$s5,$s6,$s7,$s8,$s9;
$drawCounter=0;
$dCounter=0;
for($dCounter=0; $dCounterWow! You Won!
';
echo '
';
whereWinPlayer();
echo '';
$gameOver=1;
}
if (iWin() && !$gameOver) {
echo 'Oops! You Lost!
';
echo '
';
whereWinComp();
echo '';
$gameOver=1;
}
if(draw() && !playerWin() && !iWin()) {
echo 'It's a Draw!
';
echo '
';
print '';
}
}
else
genBox($bsize);
?>
© 2004 Premshree Pillai | Sign my Guestbook.
Solution
Tic Tac Toe in PHP';
for($i=0; $i<$size; $i++) {
for($j=0; $j<$size; $j++) {
$count++;
$retVal.='';
}
$retVal.='
';
}
$retVal.='';
echo $retVal;
}
function genBox2($size,$arr) {
global
$bsize,$playerToken,$myToken,$gameOver,$winArr,$rowArr,$colArr,$digArr,$vals,$s1,$s2,$s
3,$s4,$s5,$s6,$s7,$s8,$s9;
$count=0;
$retVal='';
for($i=0; $i<$size; $i++) {
for($j=0; $j<$size; $j++) {
$count++;
$retVal.='';
}
$retVal.='
';
}
$retVal.='';
echo $retVal;
}
function isEmpty($who) {
if($who=="")
return 1;
else
return 0;
}
function move($bsize,$arr) {
global
$bsize,$playerToken,$myToken,$gameOver,$winArr,$rowArr,$colArr,$digArr,$vals,$s1,$s2,$s
3,$s4,$s5,$s6,$s7,$s8,$s9;
$count=0;
$maxCount=0;
$pos=0;
$retVal=0;
# Build Row Array
for($i=0; $i<$bsize; $i++) {
$maxCount=0;
$fullCounter=0;
for($j=0; $j<$bsize; $j++) {
$count++;
$who=$arr[$count-1];
if($who==$playerToken) {
$maxCount++;
$fullCounter++;
}
if($who==$myToken)
$fullCounter++;
}
$rowArr[$i]=$maxCount;
if($fullCounter==$bsize)
$rowArr[$i]=-1;
}
# Building Column Array
for($i=0; $i<$bsize; $i++) {
$count=$i+1;
$maxCount=0;
$fullCounter=0;
for($j=0; $j<$bsize; $j++) {
$who=$arr[$count-1];
if($who==$playerToken) {
$maxCount++;
$fullCounter++;
}
if($who==$myToken)
$fullCounter++;
$count+=$bsize;
}
$colArr[$i]=$maxCount;
if($fullCounter==$bsize)
$colArr[$i]=-1;
}
# Building Diagonal Array
for($i=0; $i<2; $i++) {
if($i==0)
$count=$i+1;
else
$count=$bsize;
$maxCount=0;
$fullCounter=0;
for($j=0; $j<$bsize; $j++) {
$who=$arr[$count-1];
if($who==$playerToken) {
$maxCount++;
$fullCounter++;
}
if($who==$myToken)
$fullCounter++;
if($i==0)
$count+=$bsize+1;
else
$count+=$bsize-1;
}
$digArr[$i]=$maxCount;
if($fullCounter==$bsize)
$digArr[$i]=-1;
}
# Finding Max Values
$maxRow=myMax(0,$bsize,"row",$rowArr);
$maxCol=myMax(0,$bsize,"col",$colArr);
$maxDig=myMax(0,$bsize,"dig",$digArr);
$maxArrs[0]=myMax(1,$bsize,"row",$rowArr);
$maxArrs[1]=myMax(1,$bsize,"col",$colArr);
$maxArrs[2]=myMax(1,$bsize,"dig",$digArr);
//$maxArrs=array(max(1,$bsize,"row",$rowArr),max(1,$bsize,"col",$colArr),max(1,$bsize,"
dig",$digArr));
if(myMax(0,$bsize,"x",$maxArrs)==0)
$pos=$bsize*($maxRow+1)-$bsize;
if(myMax(0,$bsize,"x",$maxArrs)==1)
$pos=$maxCol;
if(myMax(0,$bsize,"x",$maxArrs)==2)
if($maxDig==0)
$pos=$maxDig;
else
$pos=$bsize-1;
$retFlag=0;
for($y=0; $y<$bsize; $y++) {
if(!$retFlag) {
if($arr[$pos]=="") {
$retVal=$pos;
$retFlag=1;
}
if(myMax(0,$bsize,"x",$maxArrs)==0)
$pos++;
if(myMax(0,$bsize,"x",$maxArrs)==1)
$pos+=$bsize;
if(myMax(0,$bsize,"x",$maxArrs)==2)
if($maxDig==0)
$pos+=$bsize+1;
else
$pos+=$bsize-1;
}
}
return $retVal;
}
function myMax($what,$bsize,$type,$arr) {
global
$bsize,$playerToken,$myToken,$gameOver,$winArr,$rowArr,$colArr,$digArr,$vals,$s1,$s2,$s
3,$s4,$s5,$s6,$s7,$s8,$s9;
$max=-1;
$maxIndex=-1;
if($type!="dig") {
for($i=0; $i<$bsize; $i++) {
if($arr[$i]>$max) {
$max=$arr[$i];
$maxIndex=$i;
}
}
}
if($type=="dig") {
for($i=0; $i<2; $i++) {
if($arr[$i]>$max) {
$max=$arr[$i];
$maxIndex=$i;
}
}
}
if($what==0)
return $maxIndex;
else
return $max;
}
function playerWin() {
global
$bsize,$playerToken,$myToken,$gameOver,$winArr,$rowArr,$colArr,$digArr,$vals,$s1,$s2,$s
3,$s4,$s5,$s6,$s7,$s8,$s9;
$who=$playerToken;
if(($s1==$who && $s2==$s1 && $s3==$s1) || ($s4==$who && $s5==$s4 &&
$s6==$s4)||($s7==$who && $s8==$s7 && $s9==$s7) ||($s1==$who && $s4==$s1 &&
$s7==$s1) ||($s2==$who && $s5==$s2 && $s8==$s2) ||($s3==$who && $s6==$s3 &&
$s9==$s3) ||($s1==$who && $s5==$s1 && $s9==$s1) ||($s3==$who && $s5==$s3 &&
$s7==$s3))
return 1;
else
return 0;
}
function iWin() {
global
$bsize,$playerToken,$myToken,$gameOver,$winArr,$rowArr,$colArr,$digArr,$vals,$s1,$s2,$s
3,$s4,$s5,$s6,$s7,$s8,$s9;
$who=$myToken;
if(($s1==$who && $s2==$s1 && $s3==$s1) || ($s4==$who && $s5==$s4 &&
$s6==$s4)||($s7==$who && $s8==$s7 && $s9==$s7) ||($s1==$who && $s4==$s1 &&
$s7==$s1) ||($s2==$who && $s5==$s2 && $s8==$s2) ||($s3==$who && $s6==$s3 &&
$s9==$s3) ||($s1==$who && $s5==$s1 && $s9==$s1) ||($s3==$who && $s5==$s3 &&
$s7==$s3))
return 1;
else
return 0;
}
function whereWinComp() {
global
$bsize,$playerToken,$myToken,$gameOver,$winArr,$rowArr,$colArr,$digArr,$vals,$s1,$s2,$s
3,$s4,$s5,$s6,$s7,$s8,$s9;
$who=$myToken;
if(($s1==$who && $s2==$s1 && $s3==$s1))
$winArr=array('s1','s2','s3');
if(($s4==$who && $s5==$s4 && $s6==$s4))
$winArr=array('s4','s5','s6');
if(($s7==$who && $s8==$s7 && $s9==$s7))
$winArr=array('s7','s8','s9');
if(($s1==$who && $s4==$s1 && $s7==$s1))
$winArr=array('s1','s4','s7');
if(($s2==$who && $s5==$s2 && $s8==$s2))
$winArr=array('s2','s5','s8');
if(($s3==$who && $s6==$s3 && $s9==$s3))
$winArr=array('s3','s6','s9');
if(($s1==$who && $s5==$s1 && $s9==$s1))
$winArr=array('s1','s5','s9');
if(($s3==$who && $s5==$s3 && $s7==$s3))
$winArr=array('s3','s5','s7');
}
function whereWinPlayer() {
global
$bsize,$playerToken,$myToken,$gameOver,$winArr,$rowArr,$colArr,$digArr,$vals,$s1,$s2,$s
3,$s4,$s5,$s6,$s7,$s8,$s9;
$who=$playerToken;
if(($s1==$who && $s2==$s1 && $s3==$s1))
$winArr=array('s1','s2','s3');
if(($s4==$who && $s5==$s4 && $s6==$s4))
$winArr=array('s4','s5','s6');
if(($s7==$who && $s8==$s7 && $s9==$s7))
$winArr=array('s7','s8','s9');
if(($s1==$who && $s4==$s1 && $s7==$s1))
$winArr=array('s1','s4','s7');
if(($s2==$who && $s5==$s2 && $s8==$s2))
$winArr=array('s2','s5','s8');
if(($s3==$who && $s6==$s3 && $s9==$s3))
$winArr=array('s3','s6','s9');
if(($s1==$who && $s5==$s1 && $s9==$s1))
$winArr=array('s1','s5','s9');
if(($s3==$who && $s5==$s3 && $s7==$s3))
$winArr=array('s3','s5','s7');
}
function draw() {
global
$bsize,$playerToken,$myToken,$gameOver,$winArr,$rowArr,$colArr,$digArr,$vals,$s1,$s2,$s
3,$s4,$s5,$s6,$s7,$s8,$s9;
$drawCounter=0;
$dCounter=0;
for($dCounter=0; $dCounterWow! You Won!
';
echo '
';
whereWinPlayer();
echo '';
$gameOver=1;
}
if (iWin() && !$gameOver) {
echo 'Oops! You Lost!
';
echo '
';
whereWinComp();
echo '';
$gameOver=1;
}
if(draw() && !playerWin() && !iWin()) {
echo 'It's a Draw!
';
echo '
';
print '';
}
}
else
genBox($bsize);
?>
© 2004 Premshree Pillai | Sign my Guestbook.

More Related Content

Similar to php global $bsize,$playerToken,$myToken,$gameOver,$winArr,$rowAr.pdf

The Perl6 Type System
The Perl6 Type SystemThe Perl6 Type System
The Perl6 Type Systemabrummett
 
Taking Perl to Eleven with Higher-Order Functions
Taking Perl to Eleven with Higher-Order FunctionsTaking Perl to Eleven with Higher-Order Functions
Taking Perl to Eleven with Higher-Order FunctionsDavid Golden
 
Introduction à CoffeeScript pour ParisRB
Introduction à CoffeeScript pour ParisRB Introduction à CoffeeScript pour ParisRB
Introduction à CoffeeScript pour ParisRB jhchabran
 
Text in search queries with examples in Perl 6
Text in search queries with examples in Perl 6Text in search queries with examples in Perl 6
Text in search queries with examples in Perl 6Andrew Shitov
 
Bouncingballs sh
Bouncingballs shBouncingballs sh
Bouncingballs shBen Pope
 
Swift - 혼자 공부하면 분명히 안할테니까 같이 공부하기
Swift - 혼자 공부하면 분명히 안할테니까 같이 공부하기Swift - 혼자 공부하면 분명히 안할테니까 같이 공부하기
Swift - 혼자 공부하면 분명히 안할테니까 같이 공부하기Suyeol Jeon
 
20160227 Granma
20160227 Granma20160227 Granma
20160227 GranmaSharon Liu
 
Learning Perl 6 (NPW 2007)
Learning Perl 6 (NPW 2007)Learning Perl 6 (NPW 2007)
Learning Perl 6 (NPW 2007)brian d foy
 
Introdução ao Perl 6
Introdução ao Perl 6Introdução ao Perl 6
Introdução ao Perl 6garux
 
Perl Bag of Tricks - Baltimore Perl mongers
Perl Bag of Tricks  -  Baltimore Perl mongersPerl Bag of Tricks  -  Baltimore Perl mongers
Perl Bag of Tricks - Baltimore Perl mongersbrian d foy
 
Algorithm, Review, Sorting
Algorithm, Review, SortingAlgorithm, Review, Sorting
Algorithm, Review, SortingRowan Merewood
 
How to write code you won't hate tomorrow
How to write code you won't hate tomorrowHow to write code you won't hate tomorrow
How to write code you won't hate tomorrowPete McFarlane
 
Learning Perl 6
Learning Perl 6 Learning Perl 6
Learning Perl 6 brian d foy
 

Similar to php global $bsize,$playerToken,$myToken,$gameOver,$winArr,$rowAr.pdf (20)

The Perl6 Type System
The Perl6 Type SystemThe Perl6 Type System
The Perl6 Type System
 
Taking Perl to Eleven with Higher-Order Functions
Taking Perl to Eleven with Higher-Order FunctionsTaking Perl to Eleven with Higher-Order Functions
Taking Perl to Eleven with Higher-Order Functions
 
Introduction à CoffeeScript pour ParisRB
Introduction à CoffeeScript pour ParisRB Introduction à CoffeeScript pour ParisRB
Introduction à CoffeeScript pour ParisRB
 
Text in search queries with examples in Perl 6
Text in search queries with examples in Perl 6Text in search queries with examples in Perl 6
Text in search queries with examples in Perl 6
 
Php functions
Php functionsPhp functions
Php functions
 
Perl6 grammars
Perl6 grammarsPerl6 grammars
Perl6 grammars
 
Bouncingballs sh
Bouncingballs shBouncingballs sh
Bouncingballs sh
 
Swift - 혼자 공부하면 분명히 안할테니까 같이 공부하기
Swift - 혼자 공부하면 분명히 안할테니까 같이 공부하기Swift - 혼자 공부하면 분명히 안할테니까 같이 공부하기
Swift - 혼자 공부하면 분명히 안할테니까 같이 공부하기
 
Daily notes
Daily notesDaily notes
Daily notes
 
Database api
Database apiDatabase api
Database api
 
20160227 Granma
20160227 Granma20160227 Granma
20160227 Granma
 
CoffeeScript
CoffeeScriptCoffeeScript
CoffeeScript
 
Bag of tricks
Bag of tricksBag of tricks
Bag of tricks
 
Learning Perl 6 (NPW 2007)
Learning Perl 6 (NPW 2007)Learning Perl 6 (NPW 2007)
Learning Perl 6 (NPW 2007)
 
Introdução ao Perl 6
Introdução ao Perl 6Introdução ao Perl 6
Introdução ao Perl 6
 
Perl Bag of Tricks - Baltimore Perl mongers
Perl Bag of Tricks  -  Baltimore Perl mongersPerl Bag of Tricks  -  Baltimore Perl mongers
Perl Bag of Tricks - Baltimore Perl mongers
 
Algorithm, Review, Sorting
Algorithm, Review, SortingAlgorithm, Review, Sorting
Algorithm, Review, Sorting
 
How to write code you won't hate tomorrow
How to write code you won't hate tomorrowHow to write code you won't hate tomorrow
How to write code you won't hate tomorrow
 
R57.Php
R57.PhpR57.Php
R57.Php
 
Learning Perl 6
Learning Perl 6 Learning Perl 6
Learning Perl 6
 

More from anjalitimecenter11

O = O bond is shortest Oxygen electronegativity d.pdf
                     O = O bond is shortest Oxygen electronegativity d.pdf                     O = O bond is shortest Oxygen electronegativity d.pdf
O = O bond is shortest Oxygen electronegativity d.pdfanjalitimecenter11
 
NaCl Na is the symbol for Sodium which bonds to .pdf
                     NaCl  Na is the symbol for Sodium which bonds to .pdf                     NaCl  Na is the symbol for Sodium which bonds to .pdf
NaCl Na is the symbol for Sodium which bonds to .pdfanjalitimecenter11
 
NiCl2 because it not dissociate .pdf
                     NiCl2  because it not dissociate                 .pdf                     NiCl2  because it not dissociate                 .pdf
NiCl2 because it not dissociate .pdfanjalitimecenter11
 
iodide, I-, has the -1 oxidation state. iodine (I.pdf
                     iodide, I-, has the -1 oxidation state. iodine (I.pdf                     iodide, I-, has the -1 oxidation state. iodine (I.pdf
iodide, I-, has the -1 oxidation state. iodine (I.pdfanjalitimecenter11
 
Lithium is in group 1 on the peridic table. This .pdf
                     Lithium is in group 1 on the peridic table. This .pdf                     Lithium is in group 1 on the peridic table. This .pdf
Lithium is in group 1 on the peridic table. This .pdfanjalitimecenter11
 
y=2sin(2pix3)Solutiony=2sin(2pix3).pdf
y=2sin(2pix3)Solutiony=2sin(2pix3).pdfy=2sin(2pix3)Solutiony=2sin(2pix3).pdf
y=2sin(2pix3)Solutiony=2sin(2pix3).pdfanjalitimecenter11
 
Solution1.cpp#include iostreamheader for input output function.pdf
Solution1.cpp#include iostreamheader for input output function.pdfSolution1.cpp#include iostreamheader for input output function.pdf
Solution1.cpp#include iostreamheader for input output function.pdfanjalitimecenter11
 
Systematic positionKingdom PlantaeSubkingdom Tracheobionta (Vas.pdf
Systematic positionKingdom PlantaeSubkingdom Tracheobionta (Vas.pdfSystematic positionKingdom PlantaeSubkingdom Tracheobionta (Vas.pdf
Systematic positionKingdom PlantaeSubkingdom Tracheobionta (Vas.pdfanjalitimecenter11
 
Query to list out all the languages in the table LANGUAGES.SELECT .pdf
Query to list out all the languages in the table LANGUAGES.SELECT .pdfQuery to list out all the languages in the table LANGUAGES.SELECT .pdf
Query to list out all the languages in the table LANGUAGES.SELECT .pdfanjalitimecenter11
 
public class LunarLander {    double currentFuelFlowRate;    d.pdf
public class LunarLander {    double currentFuelFlowRate;    d.pdfpublic class LunarLander {    double currentFuelFlowRate;    d.pdf
public class LunarLander {    double currentFuelFlowRate;    d.pdfanjalitimecenter11
 
Cooling. The reaction is giving off energy(heat) .pdf
                     Cooling. The reaction is giving off energy(heat) .pdf                     Cooling. The reaction is giving off energy(heat) .pdf
Cooling. The reaction is giving off energy(heat) .pdfanjalitimecenter11
 
c. cytochrome C It is the enzyme involved in the .pdf
                     c. cytochrome C It is the enzyme involved in the .pdf                     c. cytochrome C It is the enzyme involved in the .pdf
c. cytochrome C It is the enzyme involved in the .pdfanjalitimecenter11
 
Ka=-log(Ka)=-log(5.610^-10)=9.25 According to Henderson Hasselb.pdf
Ka=-log(Ka)=-log(5.610^-10)=9.25 According to Henderson Hasselb.pdfKa=-log(Ka)=-log(5.610^-10)=9.25 According to Henderson Hasselb.pdf
Ka=-log(Ka)=-log(5.610^-10)=9.25 According to Henderson Hasselb.pdfanjalitimecenter11
 
C is wrong 14 7N contains 7 protons and 7 neutron.pdf
                     C is wrong 14 7N contains 7 protons and 7 neutron.pdf                     C is wrong 14 7N contains 7 protons and 7 neutron.pdf
C is wrong 14 7N contains 7 protons and 7 neutron.pdfanjalitimecenter11
 
1.The following are the main types of service providers to a mutua.pdf
1.The following are the main types of service providers to a mutua.pdf1.The following are the main types of service providers to a mutua.pdf
1.The following are the main types of service providers to a mutua.pdfanjalitimecenter11
 
D. planned and directed means to improve the functioning of the clie.pdf
D. planned and directed means to improve the functioning of the clie.pdfD. planned and directed means to improve the functioning of the clie.pdf
D. planned and directed means to improve the functioning of the clie.pdfanjalitimecenter11
 
domain - -x-1 0 = x+10 =x-1i.e. (-inf,-1)range-(-in.pdf
domain - -x-1 0 = x+10 =x-1i.e. (-inf,-1)range-(-in.pdfdomain - -x-1 0 = x+10 =x-1i.e. (-inf,-1)range-(-in.pdf
domain - -x-1 0 = x+10 =x-1i.e. (-inf,-1)range-(-in.pdfanjalitimecenter11
 
B.both are correctSolutionB.both are correct.pdf
B.both are correctSolutionB.both are correct.pdfB.both are correctSolutionB.both are correct.pdf
B.both are correctSolutionB.both are correct.pdfanjalitimecenter11
 
C. Keystroke loggers are a form of malware that records every key th.pdf
C. Keystroke loggers are a form of malware that records every key th.pdfC. Keystroke loggers are a form of malware that records every key th.pdf
C. Keystroke loggers are a form of malware that records every key th.pdfanjalitimecenter11
 

More from anjalitimecenter11 (20)

O = O bond is shortest Oxygen electronegativity d.pdf
                     O = O bond is shortest Oxygen electronegativity d.pdf                     O = O bond is shortest Oxygen electronegativity d.pdf
O = O bond is shortest Oxygen electronegativity d.pdf
 
NaCl Na is the symbol for Sodium which bonds to .pdf
                     NaCl  Na is the symbol for Sodium which bonds to .pdf                     NaCl  Na is the symbol for Sodium which bonds to .pdf
NaCl Na is the symbol for Sodium which bonds to .pdf
 
NiCl2 because it not dissociate .pdf
                     NiCl2  because it not dissociate                 .pdf                     NiCl2  because it not dissociate                 .pdf
NiCl2 because it not dissociate .pdf
 
iodide, I-, has the -1 oxidation state. iodine (I.pdf
                     iodide, I-, has the -1 oxidation state. iodine (I.pdf                     iodide, I-, has the -1 oxidation state. iodine (I.pdf
iodide, I-, has the -1 oxidation state. iodine (I.pdf
 
Lithium is in group 1 on the peridic table. This .pdf
                     Lithium is in group 1 on the peridic table. This .pdf                     Lithium is in group 1 on the peridic table. This .pdf
Lithium is in group 1 on the peridic table. This .pdf
 
{}Solution{}.pdf
{}Solution{}.pdf{}Solution{}.pdf
{}Solution{}.pdf
 
y=2sin(2pix3)Solutiony=2sin(2pix3).pdf
y=2sin(2pix3)Solutiony=2sin(2pix3).pdfy=2sin(2pix3)Solutiony=2sin(2pix3).pdf
y=2sin(2pix3)Solutiony=2sin(2pix3).pdf
 
Solution1.cpp#include iostreamheader for input output function.pdf
Solution1.cpp#include iostreamheader for input output function.pdfSolution1.cpp#include iostreamheader for input output function.pdf
Solution1.cpp#include iostreamheader for input output function.pdf
 
Systematic positionKingdom PlantaeSubkingdom Tracheobionta (Vas.pdf
Systematic positionKingdom PlantaeSubkingdom Tracheobionta (Vas.pdfSystematic positionKingdom PlantaeSubkingdom Tracheobionta (Vas.pdf
Systematic positionKingdom PlantaeSubkingdom Tracheobionta (Vas.pdf
 
Query to list out all the languages in the table LANGUAGES.SELECT .pdf
Query to list out all the languages in the table LANGUAGES.SELECT .pdfQuery to list out all the languages in the table LANGUAGES.SELECT .pdf
Query to list out all the languages in the table LANGUAGES.SELECT .pdf
 
public class LunarLander {    double currentFuelFlowRate;    d.pdf
public class LunarLander {    double currentFuelFlowRate;    d.pdfpublic class LunarLander {    double currentFuelFlowRate;    d.pdf
public class LunarLander {    double currentFuelFlowRate;    d.pdf
 
Cooling. The reaction is giving off energy(heat) .pdf
                     Cooling. The reaction is giving off energy(heat) .pdf                     Cooling. The reaction is giving off energy(heat) .pdf
Cooling. The reaction is giving off energy(heat) .pdf
 
c. cytochrome C It is the enzyme involved in the .pdf
                     c. cytochrome C It is the enzyme involved in the .pdf                     c. cytochrome C It is the enzyme involved in the .pdf
c. cytochrome C It is the enzyme involved in the .pdf
 
Ka=-log(Ka)=-log(5.610^-10)=9.25 According to Henderson Hasselb.pdf
Ka=-log(Ka)=-log(5.610^-10)=9.25 According to Henderson Hasselb.pdfKa=-log(Ka)=-log(5.610^-10)=9.25 According to Henderson Hasselb.pdf
Ka=-log(Ka)=-log(5.610^-10)=9.25 According to Henderson Hasselb.pdf
 
C is wrong 14 7N contains 7 protons and 7 neutron.pdf
                     C is wrong 14 7N contains 7 protons and 7 neutron.pdf                     C is wrong 14 7N contains 7 protons and 7 neutron.pdf
C is wrong 14 7N contains 7 protons and 7 neutron.pdf
 
1.The following are the main types of service providers to a mutua.pdf
1.The following are the main types of service providers to a mutua.pdf1.The following are the main types of service providers to a mutua.pdf
1.The following are the main types of service providers to a mutua.pdf
 
D. planned and directed means to improve the functioning of the clie.pdf
D. planned and directed means to improve the functioning of the clie.pdfD. planned and directed means to improve the functioning of the clie.pdf
D. planned and directed means to improve the functioning of the clie.pdf
 
domain - -x-1 0 = x+10 =x-1i.e. (-inf,-1)range-(-in.pdf
domain - -x-1 0 = x+10 =x-1i.e. (-inf,-1)range-(-in.pdfdomain - -x-1 0 = x+10 =x-1i.e. (-inf,-1)range-(-in.pdf
domain - -x-1 0 = x+10 =x-1i.e. (-inf,-1)range-(-in.pdf
 
B.both are correctSolutionB.both are correct.pdf
B.both are correctSolutionB.both are correct.pdfB.both are correctSolutionB.both are correct.pdf
B.both are correctSolutionB.both are correct.pdf
 
C. Keystroke loggers are a form of malware that records every key th.pdf
C. Keystroke loggers are a form of malware that records every key th.pdfC. Keystroke loggers are a form of malware that records every key th.pdf
C. Keystroke loggers are a form of malware that records every key th.pdf
 

Recently uploaded

How to Create Map Views in the Odoo 17 ERP
How to Create Map Views in the Odoo 17 ERPHow to Create Map Views in the Odoo 17 ERP
How to Create Map Views in the Odoo 17 ERPCeline George
 
Solid waste management & Types of Basic civil Engineering notes by DJ Sir.pptx
Solid waste management & Types of Basic civil Engineering notes by DJ Sir.pptxSolid waste management & Types of Basic civil Engineering notes by DJ Sir.pptx
Solid waste management & Types of Basic civil Engineering notes by DJ Sir.pptxDenish Jangid
 
Advances in production technology of Grapes.pdf
Advances in production technology of Grapes.pdfAdvances in production technology of Grapes.pdf
Advances in production technology of Grapes.pdfDr. M. Kumaresan Hort.
 
Basic Civil Engg Notes_Chapter-6_Environment Pollution & Engineering
Basic Civil Engg Notes_Chapter-6_Environment Pollution & EngineeringBasic Civil Engg Notes_Chapter-6_Environment Pollution & Engineering
Basic Civil Engg Notes_Chapter-6_Environment Pollution & EngineeringDenish Jangid
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaasiemaillard
 
Gyanartha SciBizTech Quiz slideshare.pptx
Gyanartha SciBizTech Quiz slideshare.pptxGyanartha SciBizTech Quiz slideshare.pptx
Gyanartha SciBizTech Quiz slideshare.pptxShibin Azad
 
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdfAdversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdfPo-Chuan Chen
 
Danh sách HSG Bộ môn cấp trường - Cấp THPT.pdf
Danh sách HSG Bộ môn cấp trường - Cấp THPT.pdfDanh sách HSG Bộ môn cấp trường - Cấp THPT.pdf
Danh sách HSG Bộ môn cấp trường - Cấp THPT.pdfQucHHunhnh
 
Benefits and Challenges of Using Open Educational Resources
Benefits and Challenges of Using Open Educational ResourcesBenefits and Challenges of Using Open Educational Resources
Benefits and Challenges of Using Open Educational Resourcesdimpy50
 
Palestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptxPalestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptxRaedMohamed3
 
slides CapTechTalks Webinar May 2024 Alexander Perry.pptx
slides CapTechTalks Webinar May 2024 Alexander Perry.pptxslides CapTechTalks Webinar May 2024 Alexander Perry.pptx
slides CapTechTalks Webinar May 2024 Alexander Perry.pptxCapitolTechU
 
Matatag-Curriculum and the 21st Century Skills Presentation.pptx
Matatag-Curriculum and the 21st Century Skills Presentation.pptxMatatag-Curriculum and the 21st Century Skills Presentation.pptx
Matatag-Curriculum and the 21st Century Skills Presentation.pptxJenilouCasareno
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaasiemaillard
 
Application of Matrices in real life. Presentation on application of matrices
Application of Matrices in real life. Presentation on application of matricesApplication of Matrices in real life. Presentation on application of matrices
Application of Matrices in real life. Presentation on application of matricesRased Khan
 
50 ĐỀ LUYỆN THI IOE LỚP 9 - NĂM HỌC 2022-2023 (CÓ LINK HÌNH, FILE AUDIO VÀ ĐÁ...
50 ĐỀ LUYỆN THI IOE LỚP 9 - NĂM HỌC 2022-2023 (CÓ LINK HÌNH, FILE AUDIO VÀ ĐÁ...50 ĐỀ LUYỆN THI IOE LỚP 9 - NĂM HỌC 2022-2023 (CÓ LINK HÌNH, FILE AUDIO VÀ ĐÁ...
50 ĐỀ LUYỆN THI IOE LỚP 9 - NĂM HỌC 2022-2023 (CÓ LINK HÌNH, FILE AUDIO VÀ ĐÁ...Nguyen Thanh Tu Collection
 
Instructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptxInstructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptxJheel Barad
 

Recently uploaded (20)

How to Create Map Views in the Odoo 17 ERP
How to Create Map Views in the Odoo 17 ERPHow to Create Map Views in the Odoo 17 ERP
How to Create Map Views in the Odoo 17 ERP
 
Solid waste management & Types of Basic civil Engineering notes by DJ Sir.pptx
Solid waste management & Types of Basic civil Engineering notes by DJ Sir.pptxSolid waste management & Types of Basic civil Engineering notes by DJ Sir.pptx
Solid waste management & Types of Basic civil Engineering notes by DJ Sir.pptx
 
Advances in production technology of Grapes.pdf
Advances in production technology of Grapes.pdfAdvances in production technology of Grapes.pdf
Advances in production technology of Grapes.pdf
 
Basic Civil Engg Notes_Chapter-6_Environment Pollution & Engineering
Basic Civil Engg Notes_Chapter-6_Environment Pollution & EngineeringBasic Civil Engg Notes_Chapter-6_Environment Pollution & Engineering
Basic Civil Engg Notes_Chapter-6_Environment Pollution & Engineering
 
NCERT Solutions Power Sharing Class 10 Notes pdf
NCERT Solutions Power Sharing Class 10 Notes pdfNCERT Solutions Power Sharing Class 10 Notes pdf
NCERT Solutions Power Sharing Class 10 Notes pdf
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
 
B.ed spl. HI pdusu exam paper-2023-24.pdf
B.ed spl. HI pdusu exam paper-2023-24.pdfB.ed spl. HI pdusu exam paper-2023-24.pdf
B.ed spl. HI pdusu exam paper-2023-24.pdf
 
Gyanartha SciBizTech Quiz slideshare.pptx
Gyanartha SciBizTech Quiz slideshare.pptxGyanartha SciBizTech Quiz slideshare.pptx
Gyanartha SciBizTech Quiz slideshare.pptx
 
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdfAdversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
 
Danh sách HSG Bộ môn cấp trường - Cấp THPT.pdf
Danh sách HSG Bộ môn cấp trường - Cấp THPT.pdfDanh sách HSG Bộ môn cấp trường - Cấp THPT.pdf
Danh sách HSG Bộ môn cấp trường - Cấp THPT.pdf
 
Benefits and Challenges of Using Open Educational Resources
Benefits and Challenges of Using Open Educational ResourcesBenefits and Challenges of Using Open Educational Resources
Benefits and Challenges of Using Open Educational Resources
 
Palestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptxPalestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptx
 
slides CapTechTalks Webinar May 2024 Alexander Perry.pptx
slides CapTechTalks Webinar May 2024 Alexander Perry.pptxslides CapTechTalks Webinar May 2024 Alexander Perry.pptx
slides CapTechTalks Webinar May 2024 Alexander Perry.pptx
 
Matatag-Curriculum and the 21st Century Skills Presentation.pptx
Matatag-Curriculum and the 21st Century Skills Presentation.pptxMatatag-Curriculum and the 21st Century Skills Presentation.pptx
Matatag-Curriculum and the 21st Century Skills Presentation.pptx
 
Ethnobotany and Ethnopharmacology ......
Ethnobotany and Ethnopharmacology ......Ethnobotany and Ethnopharmacology ......
Ethnobotany and Ethnopharmacology ......
 
Operations Management - Book1.p - Dr. Abdulfatah A. Salem
Operations Management - Book1.p  - Dr. Abdulfatah A. SalemOperations Management - Book1.p  - Dr. Abdulfatah A. Salem
Operations Management - Book1.p - Dr. Abdulfatah A. Salem
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
 
Application of Matrices in real life. Presentation on application of matrices
Application of Matrices in real life. Presentation on application of matricesApplication of Matrices in real life. Presentation on application of matrices
Application of Matrices in real life. Presentation on application of matrices
 
50 ĐỀ LUYỆN THI IOE LỚP 9 - NĂM HỌC 2022-2023 (CÓ LINK HÌNH, FILE AUDIO VÀ ĐÁ...
50 ĐỀ LUYỆN THI IOE LỚP 9 - NĂM HỌC 2022-2023 (CÓ LINK HÌNH, FILE AUDIO VÀ ĐÁ...50 ĐỀ LUYỆN THI IOE LỚP 9 - NĂM HỌC 2022-2023 (CÓ LINK HÌNH, FILE AUDIO VÀ ĐÁ...
50 ĐỀ LUYỆN THI IOE LỚP 9 - NĂM HỌC 2022-2023 (CÓ LINK HÌNH, FILE AUDIO VÀ ĐÁ...
 
Instructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptxInstructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptx
 

php global $bsize,$playerToken,$myToken,$gameOver,$winArr,$rowAr.pdf

  • 1. Tic Tac Toe in PHP'; for($i=0; $i<$size; $i++) { for($j=0; $j<$size; $j++) { $count++; $retVal.=''; } $retVal.=' '; } $retVal.=''; echo $retVal; } function genBox2($size,$arr) { global $bsize,$playerToken,$myToken,$gameOver,$winArr,$rowArr,$colArr,$digArr,$vals,$s1,$s2,$s 3,$s4,$s5,$s6,$s7,$s8,$s9; $count=0; $retVal=''; for($i=0; $i<$size; $i++) { for($j=0; $j<$size; $j++) { $count++; $retVal.=''; } $retVal.=' '; } $retVal.=''; echo $retVal; } function isEmpty($who) { if($who=="") return 1; else return 0; } function move($bsize,$arr) {
  • 2. global $bsize,$playerToken,$myToken,$gameOver,$winArr,$rowArr,$colArr,$digArr,$vals,$s1,$s2,$s 3,$s4,$s5,$s6,$s7,$s8,$s9; $count=0; $maxCount=0; $pos=0; $retVal=0; # Build Row Array for($i=0; $i<$bsize; $i++) { $maxCount=0; $fullCounter=0; for($j=0; $j<$bsize; $j++) { $count++; $who=$arr[$count-1]; if($who==$playerToken) { $maxCount++; $fullCounter++; } if($who==$myToken) $fullCounter++; } $rowArr[$i]=$maxCount; if($fullCounter==$bsize) $rowArr[$i]=-1; } # Building Column Array for($i=0; $i<$bsize; $i++) { $count=$i+1; $maxCount=0; $fullCounter=0; for($j=0; $j<$bsize; $j++) { $who=$arr[$count-1]; if($who==$playerToken) { $maxCount++; $fullCounter++;
  • 3. } if($who==$myToken) $fullCounter++; $count+=$bsize; } $colArr[$i]=$maxCount; if($fullCounter==$bsize) $colArr[$i]=-1; } # Building Diagonal Array for($i=0; $i<2; $i++) { if($i==0) $count=$i+1; else $count=$bsize; $maxCount=0; $fullCounter=0; for($j=0; $j<$bsize; $j++) { $who=$arr[$count-1]; if($who==$playerToken) { $maxCount++; $fullCounter++; } if($who==$myToken) $fullCounter++; if($i==0) $count+=$bsize+1; else $count+=$bsize-1; } $digArr[$i]=$maxCount; if($fullCounter==$bsize) $digArr[$i]=-1; } # Finding Max Values $maxRow=myMax(0,$bsize,"row",$rowArr);
  • 4. $maxCol=myMax(0,$bsize,"col",$colArr); $maxDig=myMax(0,$bsize,"dig",$digArr); $maxArrs[0]=myMax(1,$bsize,"row",$rowArr); $maxArrs[1]=myMax(1,$bsize,"col",$colArr); $maxArrs[2]=myMax(1,$bsize,"dig",$digArr); //$maxArrs=array(max(1,$bsize,"row",$rowArr),max(1,$bsize,"col",$colArr),max(1,$bsize," dig",$digArr)); if(myMax(0,$bsize,"x",$maxArrs)==0) $pos=$bsize*($maxRow+1)-$bsize; if(myMax(0,$bsize,"x",$maxArrs)==1) $pos=$maxCol; if(myMax(0,$bsize,"x",$maxArrs)==2) if($maxDig==0) $pos=$maxDig; else $pos=$bsize-1; $retFlag=0; for($y=0; $y<$bsize; $y++) { if(!$retFlag) { if($arr[$pos]=="") { $retVal=$pos; $retFlag=1; } if(myMax(0,$bsize,"x",$maxArrs)==0) $pos++; if(myMax(0,$bsize,"x",$maxArrs)==1) $pos+=$bsize; if(myMax(0,$bsize,"x",$maxArrs)==2) if($maxDig==0) $pos+=$bsize+1; else $pos+=$bsize-1; } } return $retVal;
  • 5. } function myMax($what,$bsize,$type,$arr) { global $bsize,$playerToken,$myToken,$gameOver,$winArr,$rowArr,$colArr,$digArr,$vals,$s1,$s2,$s 3,$s4,$s5,$s6,$s7,$s8,$s9; $max=-1; $maxIndex=-1; if($type!="dig") { for($i=0; $i<$bsize; $i++) { if($arr[$i]>$max) { $max=$arr[$i]; $maxIndex=$i; } } } if($type=="dig") { for($i=0; $i<2; $i++) { if($arr[$i]>$max) { $max=$arr[$i]; $maxIndex=$i; } } } if($what==0) return $maxIndex; else return $max; } function playerWin() { global $bsize,$playerToken,$myToken,$gameOver,$winArr,$rowArr,$colArr,$digArr,$vals,$s1,$s2,$s 3,$s4,$s5,$s6,$s7,$s8,$s9; $who=$playerToken; if(($s1==$who && $s2==$s1 && $s3==$s1) || ($s4==$who && $s5==$s4 && $s6==$s4)||($s7==$who && $s8==$s7 && $s9==$s7) ||($s1==$who && $s4==$s1 && $s7==$s1) ||($s2==$who && $s5==$s2 && $s8==$s2) ||($s3==$who && $s6==$s3 &&
  • 6. $s9==$s3) ||($s1==$who && $s5==$s1 && $s9==$s1) ||($s3==$who && $s5==$s3 && $s7==$s3)) return 1; else return 0; } function iWin() { global $bsize,$playerToken,$myToken,$gameOver,$winArr,$rowArr,$colArr,$digArr,$vals,$s1,$s2,$s 3,$s4,$s5,$s6,$s7,$s8,$s9; $who=$myToken; if(($s1==$who && $s2==$s1 && $s3==$s1) || ($s4==$who && $s5==$s4 && $s6==$s4)||($s7==$who && $s8==$s7 && $s9==$s7) ||($s1==$who && $s4==$s1 && $s7==$s1) ||($s2==$who && $s5==$s2 && $s8==$s2) ||($s3==$who && $s6==$s3 && $s9==$s3) ||($s1==$who && $s5==$s1 && $s9==$s1) ||($s3==$who && $s5==$s3 && $s7==$s3)) return 1; else return 0; } function whereWinComp() { global $bsize,$playerToken,$myToken,$gameOver,$winArr,$rowArr,$colArr,$digArr,$vals,$s1,$s2,$s 3,$s4,$s5,$s6,$s7,$s8,$s9; $who=$myToken; if(($s1==$who && $s2==$s1 && $s3==$s1)) $winArr=array('s1','s2','s3'); if(($s4==$who && $s5==$s4 && $s6==$s4)) $winArr=array('s4','s5','s6'); if(($s7==$who && $s8==$s7 && $s9==$s7)) $winArr=array('s7','s8','s9'); if(($s1==$who && $s4==$s1 && $s7==$s1)) $winArr=array('s1','s4','s7'); if(($s2==$who && $s5==$s2 && $s8==$s2)) $winArr=array('s2','s5','s8'); if(($s3==$who && $s6==$s3 && $s9==$s3))
  • 7. $winArr=array('s3','s6','s9'); if(($s1==$who && $s5==$s1 && $s9==$s1)) $winArr=array('s1','s5','s9'); if(($s3==$who && $s5==$s3 && $s7==$s3)) $winArr=array('s3','s5','s7'); } function whereWinPlayer() { global $bsize,$playerToken,$myToken,$gameOver,$winArr,$rowArr,$colArr,$digArr,$vals,$s1,$s2,$s 3,$s4,$s5,$s6,$s7,$s8,$s9; $who=$playerToken; if(($s1==$who && $s2==$s1 && $s3==$s1)) $winArr=array('s1','s2','s3'); if(($s4==$who && $s5==$s4 && $s6==$s4)) $winArr=array('s4','s5','s6'); if(($s7==$who && $s8==$s7 && $s9==$s7)) $winArr=array('s7','s8','s9'); if(($s1==$who && $s4==$s1 && $s7==$s1)) $winArr=array('s1','s4','s7'); if(($s2==$who && $s5==$s2 && $s8==$s2)) $winArr=array('s2','s5','s8'); if(($s3==$who && $s6==$s3 && $s9==$s3)) $winArr=array('s3','s6','s9'); if(($s1==$who && $s5==$s1 && $s9==$s1)) $winArr=array('s1','s5','s9'); if(($s3==$who && $s5==$s3 && $s7==$s3)) $winArr=array('s3','s5','s7'); } function draw() { global $bsize,$playerToken,$myToken,$gameOver,$winArr,$rowArr,$colArr,$digArr,$vals,$s1,$s2,$s 3,$s4,$s5,$s6,$s7,$s8,$s9; $drawCounter=0; $dCounter=0; for($dCounter=0; $dCounterWow! You Won!
  • 8. '; echo ' '; whereWinPlayer(); echo ''; $gameOver=1; } if (iWin() && !$gameOver) { echo 'Oops! You Lost! '; echo ' '; whereWinComp(); echo ''; $gameOver=1; } if(draw() && !playerWin() && !iWin()) { echo 'It's a Draw! '; echo ' '; print ''; } } else genBox($bsize); ?> © 2004 Premshree Pillai | Sign my Guestbook. Solution Tic Tac Toe in PHP';
  • 9. for($i=0; $i<$size; $i++) { for($j=0; $j<$size; $j++) { $count++; $retVal.=''; } $retVal.=' '; } $retVal.=''; echo $retVal; } function genBox2($size,$arr) { global $bsize,$playerToken,$myToken,$gameOver,$winArr,$rowArr,$colArr,$digArr,$vals,$s1,$s2,$s 3,$s4,$s5,$s6,$s7,$s8,$s9; $count=0; $retVal=''; for($i=0; $i<$size; $i++) { for($j=0; $j<$size; $j++) { $count++; $retVal.=''; } $retVal.=' '; } $retVal.=''; echo $retVal; } function isEmpty($who) { if($who=="") return 1; else return 0; } function move($bsize,$arr) { global
  • 10. $bsize,$playerToken,$myToken,$gameOver,$winArr,$rowArr,$colArr,$digArr,$vals,$s1,$s2,$s 3,$s4,$s5,$s6,$s7,$s8,$s9; $count=0; $maxCount=0; $pos=0; $retVal=0; # Build Row Array for($i=0; $i<$bsize; $i++) { $maxCount=0; $fullCounter=0; for($j=0; $j<$bsize; $j++) { $count++; $who=$arr[$count-1]; if($who==$playerToken) { $maxCount++; $fullCounter++; } if($who==$myToken) $fullCounter++; } $rowArr[$i]=$maxCount; if($fullCounter==$bsize) $rowArr[$i]=-1; } # Building Column Array for($i=0; $i<$bsize; $i++) { $count=$i+1; $maxCount=0; $fullCounter=0; for($j=0; $j<$bsize; $j++) { $who=$arr[$count-1]; if($who==$playerToken) { $maxCount++; $fullCounter++; }
  • 11. if($who==$myToken) $fullCounter++; $count+=$bsize; } $colArr[$i]=$maxCount; if($fullCounter==$bsize) $colArr[$i]=-1; } # Building Diagonal Array for($i=0; $i<2; $i++) { if($i==0) $count=$i+1; else $count=$bsize; $maxCount=0; $fullCounter=0; for($j=0; $j<$bsize; $j++) { $who=$arr[$count-1]; if($who==$playerToken) { $maxCount++; $fullCounter++; } if($who==$myToken) $fullCounter++; if($i==0) $count+=$bsize+1; else $count+=$bsize-1; } $digArr[$i]=$maxCount; if($fullCounter==$bsize) $digArr[$i]=-1; } # Finding Max Values $maxRow=myMax(0,$bsize,"row",$rowArr); $maxCol=myMax(0,$bsize,"col",$colArr);
  • 13. function myMax($what,$bsize,$type,$arr) { global $bsize,$playerToken,$myToken,$gameOver,$winArr,$rowArr,$colArr,$digArr,$vals,$s1,$s2,$s 3,$s4,$s5,$s6,$s7,$s8,$s9; $max=-1; $maxIndex=-1; if($type!="dig") { for($i=0; $i<$bsize; $i++) { if($arr[$i]>$max) { $max=$arr[$i]; $maxIndex=$i; } } } if($type=="dig") { for($i=0; $i<2; $i++) { if($arr[$i]>$max) { $max=$arr[$i]; $maxIndex=$i; } } } if($what==0) return $maxIndex; else return $max; } function playerWin() { global $bsize,$playerToken,$myToken,$gameOver,$winArr,$rowArr,$colArr,$digArr,$vals,$s1,$s2,$s 3,$s4,$s5,$s6,$s7,$s8,$s9; $who=$playerToken; if(($s1==$who && $s2==$s1 && $s3==$s1) || ($s4==$who && $s5==$s4 && $s6==$s4)||($s7==$who && $s8==$s7 && $s9==$s7) ||($s1==$who && $s4==$s1 && $s7==$s1) ||($s2==$who && $s5==$s2 && $s8==$s2) ||($s3==$who && $s6==$s3 && $s9==$s3) ||($s1==$who && $s5==$s1 && $s9==$s1) ||($s3==$who && $s5==$s3 &&
  • 14. $s7==$s3)) return 1; else return 0; } function iWin() { global $bsize,$playerToken,$myToken,$gameOver,$winArr,$rowArr,$colArr,$digArr,$vals,$s1,$s2,$s 3,$s4,$s5,$s6,$s7,$s8,$s9; $who=$myToken; if(($s1==$who && $s2==$s1 && $s3==$s1) || ($s4==$who && $s5==$s4 && $s6==$s4)||($s7==$who && $s8==$s7 && $s9==$s7) ||($s1==$who && $s4==$s1 && $s7==$s1) ||($s2==$who && $s5==$s2 && $s8==$s2) ||($s3==$who && $s6==$s3 && $s9==$s3) ||($s1==$who && $s5==$s1 && $s9==$s1) ||($s3==$who && $s5==$s3 && $s7==$s3)) return 1; else return 0; } function whereWinComp() { global $bsize,$playerToken,$myToken,$gameOver,$winArr,$rowArr,$colArr,$digArr,$vals,$s1,$s2,$s 3,$s4,$s5,$s6,$s7,$s8,$s9; $who=$myToken; if(($s1==$who && $s2==$s1 && $s3==$s1)) $winArr=array('s1','s2','s3'); if(($s4==$who && $s5==$s4 && $s6==$s4)) $winArr=array('s4','s5','s6'); if(($s7==$who && $s8==$s7 && $s9==$s7)) $winArr=array('s7','s8','s9'); if(($s1==$who && $s4==$s1 && $s7==$s1)) $winArr=array('s1','s4','s7'); if(($s2==$who && $s5==$s2 && $s8==$s2)) $winArr=array('s2','s5','s8'); if(($s3==$who && $s6==$s3 && $s9==$s3)) $winArr=array('s3','s6','s9');
  • 15. if(($s1==$who && $s5==$s1 && $s9==$s1)) $winArr=array('s1','s5','s9'); if(($s3==$who && $s5==$s3 && $s7==$s3)) $winArr=array('s3','s5','s7'); } function whereWinPlayer() { global $bsize,$playerToken,$myToken,$gameOver,$winArr,$rowArr,$colArr,$digArr,$vals,$s1,$s2,$s 3,$s4,$s5,$s6,$s7,$s8,$s9; $who=$playerToken; if(($s1==$who && $s2==$s1 && $s3==$s1)) $winArr=array('s1','s2','s3'); if(($s4==$who && $s5==$s4 && $s6==$s4)) $winArr=array('s4','s5','s6'); if(($s7==$who && $s8==$s7 && $s9==$s7)) $winArr=array('s7','s8','s9'); if(($s1==$who && $s4==$s1 && $s7==$s1)) $winArr=array('s1','s4','s7'); if(($s2==$who && $s5==$s2 && $s8==$s2)) $winArr=array('s2','s5','s8'); if(($s3==$who && $s6==$s3 && $s9==$s3)) $winArr=array('s3','s6','s9'); if(($s1==$who && $s5==$s1 && $s9==$s1)) $winArr=array('s1','s5','s9'); if(($s3==$who && $s5==$s3 && $s7==$s3)) $winArr=array('s3','s5','s7'); } function draw() { global $bsize,$playerToken,$myToken,$gameOver,$winArr,$rowArr,$colArr,$digArr,$vals,$s1,$s2,$s 3,$s4,$s5,$s6,$s7,$s8,$s9; $drawCounter=0; $dCounter=0; for($dCounter=0; $dCounterWow! You Won! ';
  • 16. echo ' '; whereWinPlayer(); echo ''; $gameOver=1; } if (iWin() && !$gameOver) { echo 'Oops! You Lost! '; echo ' '; whereWinComp(); echo ''; $gameOver=1; } if(draw() && !playerWin() && !iWin()) { echo 'It's a Draw! '; echo ' '; print ''; } } else genBox($bsize); ?> © 2004 Premshree Pillai | Sign my Guestbook.