I am trying to create a scrabble in php. One one hand there is a user turn and on one hand there is computer. there is only one set of pile which contains random letters.
After every user turn the computer will take random letter and place in the board.
Now I want To Find Where The word exist in the board after every turn.
this is my php code
<?php
include "config.php";
error_reporting(0);
$sql=mysql_query("SELECT * FROM animate ORDER BY RAND()") or die("query Failed");
echo "<div class='board'>";
for($row=0;$row<8;$row++){
for($column=0;$column<8;$column++){
echo "<div xy='x".$row."_y".$column."' class='empty'></div>";
}
}
echo "<div style='clear: both'></div>";
echo "</div>";
?>
Pile Of Random letters from which the nextmove will be taken
<div class='words'>
<?php
for($column=0;$column<8;$column++){
echo '<div class="'.bluexyz.'">'.
$field1 = mysql_fetch_object($sql)->code
.'</div>';
}
?>
now this is the JavaScript code for user and computer turn
var turn = Math.round(Math.random() * (1));
var player = turn;
var max = 8;
function put_val (max,pick_val){
var x = Math.round(Math.random() * (max-1));
var y = Math.round(Math.random() * (max-1));
var find_place = "x"+x+"_y"+y;
if ($(".board .empty[xy='"+find_place+"']").hasClass("empty")) {
$(".board .empty[xy='"+find_place+"']").text(pick_val);
$(".board .empty[xy='"+find_place+"']").removeClass("empty").addClass("cpu");
} else {
put_val(max,pick_val);
}
}
function cpu_turn (){
var rand_char = Math.round(Math.random() * (max-1));
$(".words div.bluexyz").each(function(i,e){
if (rand_char == i) {
var pick_val =($(this).text());
put_val(max,pick_val);
player = 0;
}
});
}
$(document).ready(function(){
// 1 = cpu
//0 = player
if (player == 1) {
cpu_turn();
} else {
alert("your turn");
}
});
var box = null;
$('.bluexyz').draggable({
revert: true,
helper: 'clone',
cursor: 'pointer',
start: function(event, ui) {
$(this).fadeTo('fast', 0.5);
},
stop: function(event, ui) {
$(this).fadeTo(0, 1);
box = $(this);
}
});
$(".empty").droppable({
drop: function(event, ui) {
var $this = $(this);
if ($(this).hasClass("empty") && player == 0) {
$this.text(ui.draggable.text());
player = 1;
$(this).removeClass("empty").addClass("user");
cpu_turn();
} else {
alert("this is full");
}
}
});
How I would be able to find the combination of word from these letters in the board.