function make_move($move, $userid, $roomid)
{
    $move--;
    if (!is_numeric($move)) {
        die;
    }
    global $db, $ir;
    $game = $db->query("SELECT * FROM bs_room WHERE id={$roomid}", $c) or die("1");
    $ga = $db->fetch_row($game);
    $turn = $ga['turn'];
    if ($turn == $userid) {
        $ginfo = $db->query("SELECT * FROM bs_game WHERE bs_room={$roomid}");
        $gin = $db->fetch_row($ginfo);
        if ($gin['p1'] == $userid) {
            $oppboard = explode('|', $gin['p2b']);
            $icoppboard = explode('|', $gin['p1bo']);
            $boardfield = "p1bo";
        } else {
            if ($gin['p2'] == $userid) {
                $oppboard = explode('|', $gin['p1b']);
                $icoppboard = explode('|', $gin['p2bo']);
                $boardfield = "p2bo";
            }
        }
        if ($icoppboard[$move] == 0) {
            if ($oppboard[$move] == 0 && ctype_digit($oppboard[$move])) {
                $oppboard[$move] = -1;
            }
            $icoppboard[$move] = $oppboard[$move];
            $uicoppboard = implode("|", $icoppboard);
            $db->query("UPDATE bs_game SET {$boardfield} = '{$uicoppboard}' WHERE bs_room = {$roomid}");
            $db->query("UPDATE bs_room SET play_time=unix_timestamp() WHERE id={$roomid}");
            $winner = check_win($roomid);
            if ($winner != 0) {
                award_win($roomid, $winner);
            } else {
                toggle_turn($roomid);
            }
            //only toggle turn if no win yet
        }
    }
}
function make_move($move, $userid, $roomid)
{
    global $db, $ir;
    $game = $db->query("SELECT * FROM ttt_room WHERE id={$roomid}", $c) or die("1");
    $ga = $db->fetch_row($game);
    $turn = $ga['turn'];
    if ($turn == $userid) {
        $ginfo = $db->query("SELECT * FROM ttt_game WHERE ttt_room={$roomid}");
        $gin = $db->fetch_row($ginfo);
        $field = "b" . $move;
        if ($gin[$field] == 0) {
            $ctime = time();
            $db->query("UPDATE ttt_game SET {$field} = {$userid} WHERE ttt_room = {$roomid}");
            $db->query("UPDATE ttt_room SET play_time=unix_timestamp() WHERE id={$roomid}");
            $winner = check_win($roomid);
            if ($winner != 0) {
                award_win($roomid, $winner);
            } else {
                toggle_turn($roomid);
            }
            //only toggle turn if no win yet
        }
    }
}
function make_move($move, $userid, $roomid)
{
    global $db, $ir;
    $game = $db->query("SELECT * FROM man_room WHERE id={$roomid}", $c) or die("1");
    $ga = $db->fetch_row($game);
    $turn = $ga['turn'];
    if ($turn == $userid) {
        $ginfo = $db->query("SELECT * FROM man_game WHERE man_room={$roomid}");
        $gin = $db->fetch_row($ginfo);
        $movefrom = "b" . $move;
        //make sure square is not empty
        if ($gin["{$movefrom}"] > 0) {
            //make sure square is on their side of the board
            if ($gin['bottom'] == $userid && $move > 0 && $move < 7 or $gin['bottom'] != $userid && $move > 7 && move < 14) {
                $totstones = $gin["{$movefrom}"];
                $gin["{$movefrom}"] = 0;
                $spot = ($move + 1) % 14;
                while ($totstones > 0) {
                    if ($spot != 7 && $spot != 0 || ($spot == 7 && $gin['bottom'] == $userid || $spot == 0 && $gin['bottom'] != $userid)) {
                        $totstones--;
                        $gin["b" . $spot] += 1;
                        $finalspot = $spot;
                        $spot++;
                    }
                    if ($spot == 7 && $gin['bottom'] != $userid || $spot == 0 && $gin['bottom'] == $userid) {
                        $spot++;
                    }
                    $spot = $spot % 14;
                }
                if ($finalspot == 0 || $finalspot == 7) {
                    $notoggle = 1;
                }
                if ($gin["b" . $finalspot] == 1 && $finalspot != 0 && $finalspot != 7) {
                    $oppspot = get_opp($finalspot);
                    if ($gin["b" . $oppspot] > 0) {
                        //only if on your side of the board
                        if ($finalspot > 0 && $finalspot < 7 && $gin['bottom'] == $userid || $finalspot > 7 && $finalspot < 14 && $gin['bottom'] != $userid) {
                            $wonstones = 1 + $gin["b" . $oppspot];
                            if ($gin['bottom'] == $userid) {
                                $gin['b7'] += $wonstones;
                            }
                            if ($gin['bottom'] != $userid) {
                                $gin['b0'] += $wonstones;
                            }
                            $gin["b" . $oppspot] = 0;
                            $gin["b" . $finalspot] = 0;
                        }
                    }
                }
                $db->query("UPDATE man_game SET b0={$gin['b0']},b1={$gin['b1']},b2={$gin['b2']},b3={$gin['b3']},b4={$gin['b4']},b5={$gin['b5']},b6={$gin['b6']},b7={$gin['b7']},b8={$gin['b8']},b9={$gin['b9']},b10={$gin['b10']},b11={$gin['b11']},b12={$gin['b12']},b13={$gin['b13']} WHERE man_room={$roomid}");
                $db->query("UPDATE man_room SET play_time=unix_timestamp() WHERE id={$roomid}");
                $winner = check_win($roomid);
                if ($winner != 0) {
                    award_win($roomid, $winner);
                } else {
                    if (!$notoggle) {
                        toggle_turn($roomid);
                    }
                }
            }
        }
    }
}
function toggle_turn($roomid)
{
    global $db, $ir;
    $ui = $db->fetch_row($db->query("SELECT p1,p2,turn FROM ms_room WHERE id = {$roomid}"));
    $db->query("UPDATE ms_game SET mselected=1 WHERE ms_room={$roomid}");
    if ($ui['turn'] == $ui['p1']) {
        $db->query("UPDATE ms_room SET notifyturn=0,play_time=unix_timestamp(),turn={$ui['p2']} WHERE id={$roomid}");
    } else {
        $db->query("UPDATE ms_room SET notifyturn=0,play_time=unix_timestamp(),turn={$ui['p1']} WHERE id={$roomid}");
    }
    $winner = check_win($roomid);
    if ($winner != 0) {
        award_win($roomid, $winner);
    }
}
function make_move($move, $userid, $roomid)
{
    global $db, $ir;
    $game = $db->query("SELECT * FROM ck_room WHERE id={$roomid}", $c) or die("1");
    $ga = $db->fetch_row($game);
    $game2 = $db->query("SELECT * FROM ck_game WHERE ck_room={$roomid}", $c) or die("1");
    $gijoe = $db->fetch_row($game2);
    $turn = $ga['turn'];
    if ($turn == $userid) {
        $vnam = "b" . $move;
        if ($move == 32) {
            $db->query("UPDATE ck_game SET pselect = 0 WHERE ck_room={$roomid}");
            die;
        }
        if ($gijoe["{$vnam}"] == $userid) {
            $db->query("UPDATE ck_game SET pselect={$move} WHERE ck_room={$roomid}");
            die;
        }
        if ($gijoe["{$vnam}"] == "-" . $userid) {
            $db->query("UPDATE ck_game SET pselect={$move} WHERE ck_room={$roomid}");
            die;
        }
        $red = $gijoe['red'];
        // get red player (used for direction on board)
        if ($gijoe['red'] == $gijoe['p1']) {
            $white = $gijoe['p2'];
        } else {
            $white = $gijoe['p1'];
        }
        $pselect = $gijoe['pselect'];
        //basic move no capture no king
        $valid = valid_move($userid, $red, $move, $pselect);
        $bmove = $gijoe[b . "{$move}"];
        $lastmove = $gijoe['lastmove'];
        $t = "b" . $gijoe[pselect];
        $user = $gijoe["{$t}"];
        if ($valid > 0 && $bmove == 0 && $lastmove == 0 && $user > 0) {
            $temp = "b" . $gijoe[pselect];
            $temp2 = "b" . $move;
            $db->query("UPDATE ck_game SET {$temp}=0, {$temp2}={$userid},pselect = {$temp2},lastmove = {$move}, lastmove2 = {$move} WHERE ck_room={$roomid}");
            $gijoe["{$temp2}"] = $userid;
            $value = king_me($userid, $red, $move);
            if ($value == 1) {
                $temp3 = "-" . $gijoe["{$temp2}"];
                $db->query("UPDATE ck_game SET {$temp2}={$temp3} WHERE ck_room={$roomid}");
            }
            end_turn($userid, $roomid);
        }
        //capture a piece
        $valid2 = jump_move($userid, $red, $white, $move, $pselect);
        $jumpedspot = $gijoe[b . "{$move}"];
        $newspot = "b" . $move;
        $jumpsomeone = $gijoe[b . "{$valid2}"];
        $user = $gijoe[b . "{$pselect}"];
        if ($valid2 > 0 && $jumpedspot == 0 && (abs($jumpsomeone) > 0 && abs($jumpsomeone) != $userid) && $user > 0) {
            $temp = "b" . $gijoe[pselect];
            // was
            $temp2 = "b" . $move;
            // going
            $temp3 = "b" . $valid2;
            //spot jumped
            $db->query("UPDATE ck_game SET {$temp}=0, {$temp2}={$userid}, pselect = {$move} ,lastmove = {$move},lastmove2 = {$move}, {$temp3} = 0 WHERE ck_room={$roomid}");
            $gijoe["{$temp2}"] = $userid;
            $value = king_me($userid, $red, $move);
            if ($value == 1) {
                $temp4 = "-" . $gijoe["{$temp2}"];
                $db->query("UPDATE ck_game SET {$temp2}={$temp4} WHERE ck_room={$roomid}");
            }
            $secondjump = array();
            $secondjump = second_jump($move, $red, $userid);
            //possible spots to
            $valid1 = jump_move($userid, $red, $white, $secondjump["d1"], $move);
            $valid2 = jump_move($userid, $red, $white, $secondjump["d2"], $move);
            $start = "b" . $move;
            $spotjumped1 = $gijoe[b . "{$valid1}"];
            $spotjumped2 = $gijoe[b . "{$valid2}"];
            $temp1 = $secondjump["d1"];
            $temp2 = $secondjump["d2"];
            $finish1 = $gijoe[b . "{$temp1}"];
            $finish2 = $gijoe[b . "{$temp2}"];
            if ($valid1 > 0 && $finish1 == 0 && ($spotjumped1 != 0 && abs($spotjumped1) != $userid) || $valid2 > 0 && $finish2 == 0 && ($spotjumped2 != 0 && abs($spotjumped2) != $userid)) {
                $themissionary = 69;
                $db->query("UPDATE ck_game SET lastmove2=0 WHERE ck_room={$roomid}");
            } else {
                end_turn($userid, $roomid);
            }
        }
        //king moves normal move
        $valid = valid_king_move($userid, $red, $move, $pselect);
        $bmove = $gijoe[b . "{$move}"];
        $lastmove = $gijoe['lastmove'];
        $isaking = $gijoe[pselect];
        $kingvalue = $gijoe[b . "{$isaking}"];
        if ($valid > 0 && $bmove == 0 && $lastmove == 0 && $kingvalue < 0) {
            $temp = "b" . $gijoe[pselect];
            $temp2 = "b" . $move;
            $user = $gijoe["{$temp}"];
            $db->query("UPDATE ck_game SET {$temp}=0, {$temp2}='{$user}',pselect = {$temp2},lastmove = {$move}, lastmove2 = {$move} WHERE ck_room={$roomid}");
            $gijoe["{$temp2}"] = $userid;
            end_turn($userid, $roomid);
        }
        //king jump
        //king_second($lastmove, $red, $userid) // possible moves
        //function king_jump($userid,$red,$white,$move,$pselect)
        $valid = king_jump($userid, $red, $white, $move, $pselect);
        $jumptoo = $gijoe[b . "{$move}"];
        //value of new spot
        $newspot = "b" . $move;
        //name of new spot
        $spotjumped = $gijoe[b . "{$valid}"];
        //value of spot jumped
        $user = abs($gijoe[b . "{$pselect}"]);
        //user value of starting spot
        $isaking = $gijoe[pselect];
        $kingvalue = $gijoe[b . "{$isaking}"];
        if ($valid > 0 && $jumptoo == 0 && (abs($spotjumped) > 0 && abs($spotjumped) != $userid) && abs($user) > 0 && $kingvalue < 0) {
            $temp = "b" . $gijoe[pselect];
            // was
            $temp2 = "b" . $move;
            // going
            $temp3 = "b" . $valid;
            //spot jumped
            $neguser = "-" . $userid;
            $db->query("UPDATE ck_game SET {$temp}=0, {$temp2}={$neguser}, pselect = {$move} ,lastmove = {$move},lastmove2 = {$move}, {$temp3} = 0 WHERE ck_room={$roomid}");
            $gijoe["{$temp2}"] = "-" . $userid;
            //second jump
            $secondjump = array();
            $secondjump = king_second($move, $red, $userid);
            //possible spots to
            $valid1 = king_jump($userid, $red, $white, $secondjump["d1"], $move);
            $valid2 = king_jump($userid, $red, $white, $secondjump["d2"], $move);
            $valid3 = king_jump($userid, $red, $white, $secondjump["d3"], $move);
            $valid4 = king_jump($userid, $red, $white, $secondjump["d4"], $move);
            $start = "b" . $move;
            $spotjumped1 = $gijoe[b . "{$valid1}"];
            $spotjumped2 = $gijoe[b . "{$valid2}"];
            $spotjumped3 = $gijoe[b . "{$valid3}"];
            $spotjumped4 = $gijoe[b . "{$valid4}"];
            $temp1 = $secondjump["d1"];
            $temp2 = $secondjump["d2"];
            $temp3 = $secondjump["d3"];
            $temp4 = $secondjump["d4"];
            $finish1 = $gijoe[b . "{$temp1}"];
            $finish2 = $gijoe[b . "{$temp2}"];
            $finish3 = $gijoe[b . "{$temp3}"];
            $finish4 = $gijoe[b . "{$temp4}"];
            if ($valid1 > 0 && $finish1 == 0 && ($spotjumped1 > 0 && abs($spotjumped1) != $userid) || $valid2 > 0 && $finish2 == 0 && ($spotjumped2 > 0 && abs($spotjumped2) != $userid) || $valid3 > 0 && $finish3 == 0 && ($spotjumped3 > 0 && abs($spotjumped3) != $userid) || $valid4 > 0 && $finish4 == 0 && ($spotjumped4 > 0 && abs($spotjumped4) != $userid)) {
                $themissionary = 69;
                $db->query("UPDATE ck_game SET lastmove2=0 WHERE ck_room={$roomid}");
            } else {
                end_turn($userid, $roomid);
            }
        }
        $winner = check_win($roomid);
        if ($winner != 0) {
            award_win($roomid, $winner);
        }
    }
}
function make_move($move, $userid, $roomid)
{
    global $db, $ir;
    $game = $db->query("SELECT * FROM or_room WHERE id={$roomid}", $c) or die("1");
    $ga = $db->fetch_row($game);
    $turn = $ga['turn'];
    if ($turn != $userid) {
        die;
    }
    //not your turn
    $ginf = $db->query("SELECT * FROM or_game WHERE or_room = {$roomid}");
    $gin = $db->fetch_row($ginf);
    if ($gin["b" . $move] > 0) {
        die;
    }
    //square not empty
    //horizontal right
    $good = 0;
    $loop = 1;
    $goodmove = 0;
    $nextspace = $move;
    while ($loop) {
        $loop = 0;
        $nextspace = $nextspace + 1;
        $gin["b" . $nextspace];
        if ($gin["b" . $nextspace] > 0 && $gin["b" . $nextspace] != $userid) {
            if (!$good) {
                $good = 1;
            }
            //set flag for valid moves.
            $loop = 1;
        }
        if ($gin["b" . $nextspace] > 0 && $gin["b" . $nextspace] == $userid && $good == 1) {
            //valid move
            $goodmove = 1;
            $endloc = $nextspace;
        }
    }
    if ($goodmove == 1) {
        $begin = $move;
        $end = $endloc;
        $finishturn = 1;
        $updatearr = array();
        for ($i = $move; $i < $endloc; $i++) {
            $updatearr[] = "b{$i}={$userid}";
        }
        $updatestr = implode(",", $updatearr);
        $db->query("UPDATE or_game SET {$updatestr} WHERE or_room={$roomid}");
    }
    //horizontal left
    $good = 0;
    $goodmove = 0;
    $loop = 1;
    $nextspace = $move;
    while ($loop) {
        $loop = 0;
        $nextspace = $nextspace - 1;
        $gin["b" . $nextspace];
        if ($gin["b" . $nextspace] > 0 && $gin["b" . $nextspace] != $userid) {
            if (!$good) {
                $good = 1;
            }
            //set flag for valid moves.
            $loop = 1;
        }
        if ($gin["b" . $nextspace] > 0 && $gin["b" . $nextspace] == $userid && $good == 1) {
            //valid move
            $goodmove = 1;
            $endloc = $nextspace;
        }
    }
    if ($goodmove == 1) {
        $begin = $move;
        $end = $endloc;
        $finishturn = 1;
        $updatearr = array();
        for ($i = $move; $i > $endloc; $i--) {
            $updatearr[] = "b{$i}={$userid}";
        }
        $updatestr = implode(",", $updatearr);
        $db->query("UPDATE or_game SET {$updatestr} WHERE or_room={$roomid}");
    }
    //vertical down
    $good = 0;
    $loop = 1;
    $goodmove = 0;
    $nextspace = $move;
    while ($loop) {
        $loop = 0;
        $nextspace = $nextspace + 10;
        $gin["b" . $nextspace];
        if ($gin["b" . $nextspace] > 0 && $gin["b" . $nextspace] != $userid) {
            if (!$good) {
                $good = 1;
            }
            //set flag for valid moves.
            $loop = 1;
        }
        if ($gin["b" . $nextspace] > 0 && $gin["b" . $nextspace] == $userid && $good == 1) {
            //valid move
            $goodmove = 1;
            $endloc = $nextspace;
        }
    }
    if ($goodmove == 1) {
        $begin = $move;
        $end = $endloc;
        $finishturn = 1;
        $updatearr = array();
        for ($i = $move; $i < $endloc; $i += 10) {
            $updatearr[] = "b{$i}={$userid}";
        }
        $updatestr = implode(",", $updatearr);
        $db->query("UPDATE or_game SET {$updatestr} WHERE or_room={$roomid}");
    }
    //vertical up
    $good = 0;
    $loop = 1;
    $goodmove = 0;
    $nextspace = $move;
    while ($loop) {
        $loop = 0;
        $nextspace = $nextspace - 10;
        $gin["b" . $nextspace];
        if ($gin["b" . $nextspace] > 0 && $gin["b" . $nextspace] != $userid) {
            if (!$good) {
                $good = 1;
            }
            //set flag for valid moves.
            $loop = 1;
        }
        if ($gin["b" . $nextspace] > 0 && $gin["b" . $nextspace] == $userid && $good == 1) {
            //valid move
            $goodmove = 1;
            $endloc = $nextspace;
        }
    }
    if ($goodmove == 1) {
        $begin = $move;
        $end = $endloc;
        $finishturn = 1;
        $updatearr = array();
        for ($i = $move; $i > $endloc; $i -= 10) {
            $updatearr[] = "b{$i}={$userid}";
        }
        $updatestr = implode(",", $updatearr);
        $db->query("UPDATE or_game SET {$updatestr} WHERE or_room={$roomid}");
    }
    //diagnol down right
    $good = 0;
    $loop = 1;
    $goodmove = 0;
    $nextspace = $move;
    while ($loop) {
        $loop = 0;
        $nextspace = $nextspace + 11;
        $gin["b" . $nextspace];
        if ($gin["b" . $nextspace] > 0 && $gin["b" . $nextspace] != $userid) {
            if (!$good) {
                $good = 1;
            }
            //set flag for valid moves.
            $loop = 1;
        }
        if ($gin["b" . $nextspace] > 0 && $gin["b" . $nextspace] == $userid && $good == 1) {
            //valid move
            $goodmove = 1;
            $endloc = $nextspace;
        }
    }
    if ($goodmove == 1) {
        $begin = $move;
        $end = $endloc;
        $finishturn = 1;
        $updatearr = array();
        for ($i = $move; $i < $endloc; $i += 11) {
            $updatearr[] = "b{$i}={$userid}";
        }
        $updatestr = implode(",", $updatearr);
        $db->query("UPDATE or_game SET {$updatestr} WHERE or_room={$roomid}");
    }
    //diagnol down left
    $good = 0;
    $loop = 1;
    $goodmove = 0;
    $nextspace = $move;
    while ($loop) {
        $loop = 0;
        $nextspace = $nextspace + 9;
        $gin["b" . $nextspace];
        if ($gin["b" . $nextspace] > 0 && $gin["b" . $nextspace] != $userid) {
            if (!$good) {
                $good = 1;
            }
            //set flag for valid moves.
            $loop = 1;
        }
        if ($gin["b" . $nextspace] > 0 && $gin["b" . $nextspace] == $userid && $good == 1) {
            //valid move
            $goodmove = 1;
            $endloc = $nextspace;
        }
    }
    if ($goodmove == 1) {
        $begin = $move;
        $end = $endloc;
        $finishturn = 1;
        $updatearr = array();
        for ($i = $move; $i < $endloc; $i += 9) {
            $updatearr[] = "b{$i}={$userid}";
        }
        $updatestr = implode(",", $updatearr);
        $db->query("UPDATE or_game SET {$updatestr} WHERE or_room={$roomid}");
    }
    //diagnol up right
    $good = 0;
    $loop = 1;
    $goodmove = 0;
    $nextspace = $move;
    while ($loop) {
        $loop = 0;
        $nextspace = $nextspace - 9;
        $gin["b" . $nextspace];
        if ($gin["b" . $nextspace] > 0 && $gin["b" . $nextspace] != $userid) {
            if (!$good) {
                $good = 1;
            }
            //set flag for valid moves.
            $loop = 1;
        }
        if ($gin["b" . $nextspace] > 0 && $gin["b" . $nextspace] == $userid && $good == 1) {
            //valid move
            $goodmove = 1;
            $endloc = $nextspace;
        }
    }
    if ($goodmove == 1) {
        $begin = $move;
        $end = $endloc;
        $finishturn = 1;
        $updatearr = array();
        for ($i = $move; $i > $endloc; $i -= 9) {
            $updatearr[] = "b{$i}={$userid}";
        }
        $updatestr = implode(",", $updatearr);
        $db->query("UPDATE or_game SET {$updatestr} WHERE or_room={$roomid}");
    }
    //diaganol up left
    $good = 0;
    $loop = 1;
    $goodmove = 0;
    $nextspace = $move;
    while ($loop) {
        $loop = 0;
        $nextspace = $nextspace - 11;
        $gin["b" . $nextspace];
        if ($gin["b" . $nextspace] > 0 && $gin["b" . $nextspace] != $userid) {
            if (!$good) {
                $good = 1;
            }
            //set flag for valid moves.
            $loop = 1;
        }
        if ($gin["b" . $nextspace] > 0 && $gin["b" . $nextspace] == $userid && $good == 1) {
            //valid move
            $goodmove = 1;
            $endloc = $nextspace;
        }
    }
    if ($goodmove == 1) {
        $begin = $move;
        $end = $endloc;
        $finishturn = 1;
        $updatearr = array();
        for ($i = $move; $i > $endloc; $i -= 11) {
            $updatearr[] = "b{$i}={$userid}";
        }
        $updatestr = implode(",", $updatearr);
        $db->query("UPDATE or_game SET {$updatestr} WHERE or_room={$roomid}");
    }
    if ($finishturn == 1) {
        $db->query("UPDATE or_game SET lastmove={$move} WHERE or_room={$roomid}");
        $winner = check_win($roomid);
        if ($winner != 0) {
            award_win($roomid, $winner);
        } else {
            toggle_turn($roomid);
        }
        //only toggle turn if no win yet
    }
}
    $oppmark = " {$person1mark}";
}
$vstxt = "<h3>{$ir['username']} ({$myrating} - {$mymark}) vs. {$opponent} ({$opprating} - {$oppmark})</h3>";
if ($ga['p1'] > 0 && $ga['p2'] > 0 && $gamerunning == 0) {
    //game not yet started
    create_game($ga['id']);
} else {
    if (($ga['p1'] > 0 && $ga['p2'] == 0 || $ga['p1'] == 0 && $ga['p2'] > 0) && $gamerunning == 1 && $ga['play_time'] != 0) {
        //game started, other player left, award win, unless no moves yet made
        if ($ga['p1'] > 0) {
            $winner = $ga['p1'];
        } else {
            $winner = $ga['p2'];
        }
        if ($gi['winner'] == 0) {
            award_win($roomid, $winner);
            $defaultwin = "Opponent left, so you won the game (along with any bets).";
        } else {
            $defaultwin = "Opponent left.";
        }
        set_up_replay($roomid, $winner, -1, $ga['bet']);
    } else {
        if ($ga['p1'] > 0 && $ga['p2'] == 0 || $ga['p1'] == 0 && $ga['p2'] > 0) {
            $waittxt = "Waiting for another person to join...";
            $vstxt = "";
        }
    }
}
if ($move) {
    if ($userid == $ga['p1']) {
        $missfield = "p1missed";
function make_move($move, $userid, $roomid)
{
    global $db, $ir;
    $game = $db->query("SELECT * FROM bg_room WHERE id={$roomid}", $c) or die("1");
    $ga = $db->fetch_row($game);
    $turn = $ga['turn'];
    $catch = 0;
    if ($turn == $userid) {
        $ginfo = $db->query("SELECT * FROM bg_game WHERE bg_room={$roomid}");
        $gin = $db->fetch_row($ginfo);
        if ($userid == $gin['black']) {
            $movefrom = "b" . $move;
        } else {
            $movefrom = "a" . $move;
        }
        $dsel = $gin['dselected'];
        // which dice is selected
        $dval = $gin["d" . $dsel];
        // value of dice selected
        $dname = "d" . $dsel;
        if ($gin["{$movefrom}"] > 0 || $userid == $gin['black'] && $gin['bbar'] > 0 && $move == 26 || $userid != $gin['black'] && $gin['abar'] > 0 && $move == 27) {
            if ($userid == $gin['black']) {
                $nextspot = $move + $dval;
                //normal move
                if ($gin["a" . $nextspot] <= 1 && $nextspot < 25 && $gin['bbar'] == 0) {
                    $temp = "b" . $nextspot;
                    $temp2 = "a" . $nextspot;
                    if ($gin["a" . $nextspot] == 1) {
                        $db->query("UPDATE bg_game SET abar = abar + 1, {$temp2}=0 WHERE bg_room={$roomid}");
                    }
                    $db->query("UPDATE bg_game SET {$temp}={$temp}+1,{$movefrom}={$movefrom}-1,{$dname} = 0,dselected = 0 WHERE bg_room={$roomid}");
                    $db->query("UPDATE bg_room SET play_time=unix_timestamp() WHERE id={$roomid}");
                    $gin["{$dname}"] = 0;
                }
                //if they have pieces on the bar
                if ($gin['bbar'] > 0 && $move == 26) {
                    if ($gin["a" . $dval] <= 1) {
                        $temp = "b" . $dval;
                        $temp2 = "a" . $dval;
                        if ($gin["a" . $dval] == 1) {
                            $db->query("UPDATE bg_game SET abar = abar + 1, {$temp2}=0 WHERE bg_room={$roomid}");
                        }
                        $db->query("UPDATE bg_game SET {$temp}={$temp}+1,bbar=bbar-1,{$dname} = 0,dselected = 0 WHERE bg_room={$roomid}");
                        $db->query("UPDATE bg_room SET play_time=unix_timestamp() WHERE id={$roomid}");
                        $gin["{$dname}"] = 0;
                    }
                }
                //moving into home
                if ($nextspot >= 25 && $move != 26 && $move != 27 && $gin['bbar'] == 0) {
                    $temp = $gin['b19'] + $gin['b20'] + $gin['b21'] + $gin['b22'] + $gin['b23'] + $gin['b24'] + $gin['b25'];
                    if ($temp == 15) {
                        $temp = "b" . $move;
                        $db->query("UPDATE bg_game SET b25=b25+1, {$temp} = {$temp} -1,{$dname} = 0,dselected = 0 WHERE bg_room={$roomid}");
                        $db->query("UPDATE bg_room SET play_time=unix_timestamp() WHERE id={$roomid}");
                        $gin["{$dname}"] = 0;
                    }
                    $winner = check_win($roomid);
                    if ($winner != 0) {
                        $catch = 1;
                        award_win($roomid, $winner);
                    }
                }
            } else {
                $nextspot = $move - $dval;
                //normal move
                if ($gin["b" . $nextspot] <= 1 && $nextspot > 0 && $gin['abar'] == 0) {
                    $temp = "a" . $nextspot;
                    $temp2 = "b" . $nextspot;
                    if ($gin["b" . $nextspot] == 1) {
                        $db->query("UPDATE bg_game SET bbar = bbar + 1, {$temp2}=0 WHERE bg_room={$roomid}");
                    }
                    $db->query("UPDATE bg_game SET {$temp}={$temp}+1,{$movefrom}={$movefrom}-1,{$dname} = 0,dselected = 0 WHERE bg_room={$roomid}");
                    $db->query("UPDATE bg_room SET play_time=unix_timestamp() WHERE id={$roomid}");
                    $gin["{$dname}"] = 0;
                }
                //if they have pieces on the bar
                if ($gin['abar'] > 0 && $move == 27) {
                    $temp2 = 25 - $dval;
                    $temp = "a" . $temp2;
                    $temp3 = "b" . $temp2;
                    if ($gin["{$temp3}"] <= 1) {
                        if ($gin["{$temp3}"] == 1) {
                            $db->query("UPDATE bg_game SET bbar = bbar + 1, {$temp3}=0 WHERE bg_room={$roomid}");
                        }
                        $db->query("UPDATE bg_game SET {$temp}={$temp}+1,abar=abar-1,{$dname} = 0,dselected = 0 WHERE bg_room={$roomid}");
                        $db->query("UPDATE bg_room SET play_time=unix_timestamp() WHERE id={$roomid}");
                        $gin["{$dname}"] = 0;
                    }
                }
                //moving into home
                if ($nextspot <= 0 && $move != 26 && $move != 27 && $gin['abar'] == 0) {
                    $temp = $gin['a0'] + $gin['a1'] + $gin['a2'] + $gin['a3'] + $gin['a4'] + $gin['a5'] + $gin['a6'];
                    if ($temp == 15) {
                        $temp = "a" . $move;
                        $db->query("UPDATE bg_game SET a0=a0+1, {$temp} = {$temp} -1,{$dname} = 0,dselected = 0 WHERE bg_room={$roomid}");
                        $db->query("UPDATE bg_room SET play_time=unix_timestamp() WHERE id={$roomid}");
                        $gin["{$dname}"] = 0;
                    }
                    $winner = check_win($roomid);
                    if ($winner != 0) {
                        $catch = 1;
                        award_win($roomid, $winner);
                    }
                }
            }
            //check for end of turn
            if ($gin['d1'] == 0 && $gin['d2'] == 0 && $gin['d3'] == 0 && $gin['d4'] == 0) {
                if ($catch == 0) {
                    toggle_turn($roomid);
                }
                //only toggle turn if no win yet
            }
            //select last die
            if ($gin['d1'] > 0 && $gin['d2'] == 0 && $gin['d3'] == 0 && $gin['d4'] == 0) {
                $db->query("UPDATE bg_game SET dselected=1 WHERE bg_room={$roomid}");
            }
            if ($gin['d1'] == 0 && $gin['d2'] > 0 && $gin['d3'] == 0 && $gin['d4'] == 0) {
                $db->query("UPDATE bg_game SET dselected=2 WHERE bg_room={$roomid}");
            }
            if ($gin['d1'] == 0 && $gin['d2'] == 0 && $gin['d3'] > 0 && $gin['d4'] == 0) {
                $db->query("UPDATE bg_game SET dselected=3 WHERE bg_room={$roomid}");
            }
            if ($gin['d1'] == 0 && $gin['d2'] == 0 && $gin['d3'] == 0 && $gin['d4'] > 0) {
                $db->query("UPDATE bg_game SET dselected=4 WHERE bg_room={$roomid}");
            }
        }
    } else {
        //print "<a href=\"http://www.seanybob.net/fail.html\" onclick=\"window.open('http://www.seanybob.net/fail.html','popup','width=500,height=500,scrollbars=no,resizable=no,toolbar=no,directories=no,location=no,menubar=no,status=no,left=0,top=0'); return false\">About</a>";
    }
}
function make_move($move, $userid, $roomid)
{
    global $db, $ir;
    $game = $db->query("SELECT * FROM st_room WHERE id={$roomid}", $c) or die("1");
    $ga = $db->fetch_row($game);
    $game2 = $db->query("SELECT * FROM st_game WHERE st_room={$roomid}", $c) or die("1");
    $gijoe = $db->fetch_row($game2);
    $turn = $ga['turn'];
    $red = $gijoe['red'];
    if ($gijoe['p1'] == $red) {
        $blue = $gijoe['p2'];
    } else {
        $blue = $gijoe['p1'];
    }
    $pselect = $gijoe['pselected'];
    $uname = $db->fetch_row($db->query("SELECT username FROM users WHERE userid={$userid}"));
    $attackersusername = $uname['username'];
    if ($userid == $red) {
        $uname = $db->fetch_row($db->query("SELECT username FROM users WHERE userid={$blue}"));
    } else {
        $uname = $db->fetch_row($db->query("SELECT username FROM users WHERE userid={$red}"));
    }
    $defendersusername = $uname['username'];
    if ($turn == $userid) {
        if ($userid == $red) {
            $loc = "a";
            $antiloc = "b";
        } else {
            $loc = "b";
            $antiloc = "a";
        }
        if ($pselect == $move) {
            $db->query("UPDATE st_game SET pselected = 0 WHERE st_room={$roomid}");
            die;
        }
        //deselect their piece
        if ($gijoe[$loc . $move] != 0) {
            $db->query("UPDATE st_game SET pselected = {$move} WHERE st_room={$roomid}");
            die;
        }
        //basic moves
        //pselect working and deselect working basic moves so normal pieces can move.
        $piecetomove = $gijoe[$loc . $pselect];
        //out of bounds
        if ($move == 56 || $move == 46 || $move == 53 || $move == 43) {
            die;
        }
        if ($move < 11 || $move > 88 || $move == 19 || $move == 29 || $move == 39 || $move == 49 || $move == 59 || $move == 69 || $move == 79) {
            die;
        }
        //movement of linear pieces
        if (abs($piecetomove) > 0 && abs($piecetomove) < 7 || abs($piecetomove) == 8) {
            if ($gijoe[$antiloc . $move] != 0) {
                //if the oppent has a piece there ATTACK
                if (valid_move($pselect, $move) == 1) {
                    $piece1 = $gijoe[$loc . $pselect];
                    //attacker
                    $piece2 = $gijoe[$antiloc . $move];
                    //defender
                    if (attack_piece(abs($piece1), abs($piece2)) == 2) {
                        $startingspot = $loc . $pselect;
                        //start spot
                        $finishingspot = $loc . $move;
                        //finishing spot
                        $revealedpiece = "-" . abs($gijoe[$startingspot]);
                        // reveal the piece
                        $opponentsspot = $antiloc . $move;
                        // losers spot
                        $Attackname = number_to_name(abs($piece1));
                        // name of attackers piece
                        $Defendname = number_to_name(abs($piece2));
                        // name of defenders piece
                        $text = $attackersusername . "\\'s " . $Attackname . " (" . abs($piece1) . ") killed " . $defendersusername . "\\'s " . $Defendname . " (" . abs($piece2) . ")";
                        $piecelost = "p" . $loc . abs($piece2);
                        //piece captured
                        $newmovelist = move_list($pselect, $move, $gijoe['listofmoves'], $gijoe['posa'], $attackersusername, $defendersusername);
                        $db->query("UPDATE st_game SET listofmoves = '{$newmovelist}', {$piecelost} = {$piecelost} +1,{$startingspot} = 0, {$finishingspot} = {$revealedpiece}, {$opponentsspot} = 0, lastmove = {$move}, battletxt = '{$text}' WHERE st_room={$roomid}");
                        toggle_turn($roomid);
                    } else {
                        if (attack_piece(abs($piece1), abs($piece2)) == 1) {
                            $startingspot = $loc . $pselect;
                            $finishingspot = $antiloc . $move;
                            $piecesname = number_to_name(abs($piece1));
                            // name of the two pieces
                            $text = "Both " . $piecesname . "\\'s (" . abs($piece1) . ") were killed";
                            $piecelost = "p" . $loc . abs($piece2);
                            // piece captured
                            $piecelost2 = "p" . $antiloc . abs($piece1);
                            //piece lost
                            $newmovelist = move_list($pselect, $move, $gijoe['listofmoves'], $gijoe['posa'], $attackersusername, $defendersusername);
                            $db->query("UPDATE st_game SET listofmoves = '{$newmovelist}', {$piecelost} = {$piecelost} +1,{$piecelost2} = {$piecelost2} +1,{$startingspot} = 0, {$finishingspot} = 0, lastmove = {$move}, battletxt = '{$text}' WHERE st_room={$roomid}");
                            toggle_turn($roomid);
                        } else {
                            if (attack_piece(abs($piece1), abs($piece2)) == 3) {
                                $winningpiece = number_to_name(abs($piece1));
                                // name of the two pieces
                                $text = $attackersusername . "\\'s " . $winnpiece . " (" . abs($piece1) . ") captured the flag";
                                $newmovelist = move_list($pselect, $move, $gijoe['listofmoves'], $gijoe['posa'], $attackersusername, $defendersusername);
                                $db->query("UPDATE st_game SET listofmoves = '{$newmovelist}', battletxt = '{$text}' WHERE st_room={$roomid}");
                                award_win($roomid, $userid);
                            } else {
                                $Attackname = number_to_name(abs($piece1));
                                // name of attackers piece
                                $Defendname = number_to_name(abs($piece2));
                                // name of defenders piece
                                $text = $attackersusername . "\\'s " . $Attackname . " (" . abs($piece1) . ") lost to " . $defendersusername . "\\'s " . $Defendname . " (" . abs($piece2) . ")";
                                $startingspot = $loc . $pselect;
                                $finishingspot = $antiloc . $move;
                                $revealedpiece = "-" . abs($gijoe[$finishingspot]);
                                $piecelost = "p" . $antiloc . abs($piece1);
                                $newmovelist = move_list($pselect, $move, $gijoe['listofmoves'], $gijoe['posa'], $attackersusername, $defendersusername);
                                $db->query("UPDATE st_game SET listofmoves = '{$newmovelist}', {$piecelost} = {$piecelost} +1,{$startingspot} = 0, {$finishingspot} = {$revealedpiece}, lastmove = {$move}, battletxt = '{$text}' WHERE st_room={$roomid}");
                                toggle_turn($roomid);
                            }
                        }
                    }
                }
            } else {
                if ($gijoe[$loc . $move] == 0) {
                    if (valid_move($pselect, $move) == 1) {
                        $startingspot = $loc . $pselect;
                        $finishingspot = $loc . $move;
                        $piecetomove = $gijoe[$startingspot];
                        $newmovelist = move_list($pselect, $move, $gijoe['listofmoves'], $gijoe['posa'], $attackersusername, $defendersusername);
                        $db->query("UPDATE st_game SET listofmoves = '{$newmovelist}', {$startingspot} = 0, {$finishingspot} = {$piecetomove}, pselected = 0, lastmove = {$move}, battletxt = '' WHERE st_room={$roomid}");
                        toggle_turn($roomid);
                    }
                }
            }
        }
        //movement of scout
        if (abs($piecetomove) == 7) {
            if ($gijoe[$antiloc . $move] != 0) {
                //if the oppent has a piece there ATTACK
                $scoutresults = array();
                $scoutresults = valid_scout($pselect, $move);
                $differenceofspots = $scoutresults['distance'];
                $direction = $scoutresults['direction'];
                if ($differenceofspots > 0) {
                    $openspots = 1;
                    for ($i = 1; $i < $differenceofspots; $i++) {
                        if ($direction == 4) {
                            $checklake = $pselect + $i;
                            if ($checklake == 56 || $checklake == 46 || $checklake == 53 || $checklake == 43) {
                                $openspots = 0;
                            }
                            $temp1 = $loc . ($pselect + $i);
                            $temp2 = $antiloc . ($pselect + $i);
                            $openplayer = $gijoe[$temp1];
                            $openopponent = $gijoe[$temp2];
                            if ($openplayer != 0 || $openopponent != 0) {
                                $openspots = 0;
                            }
                        }
                        if ($direction == 3) {
                            $checklake = $pselect - $i;
                            if ($checklake == 56 || $checklake == 46 || $checklake == 53 || $checklake == 43) {
                                $openspots = 0;
                            }
                            $temp1 = $loc . ($pselect - $i);
                            $temp2 = $antiloc . ($pselect - $i);
                            $openplayer = $gijoe[$temp1];
                            $openopponent = $gijoe[$temp2];
                            if ($openplayer != 0 || $openopponent != 0) {
                                $openspots = 0;
                            }
                        }
                        if ($direction == 2) {
                            $movevalue = $i . "0";
                            $checklake = $pselect - $movevalue;
                            if ($checklake == 56 || $checklake == 46 || $checklake == 53 || $checklake == 43) {
                                $openspots = 0;
                            }
                            $temp1 = $loc . ($pselect - $movevalue);
                            $temp2 = $antiloc . ($pselect - $movevalue);
                            $openplayer = $gijoe[$temp1];
                            $openopponent = $gijoe[$temp2];
                            if ($openplayer != 0 || $openopponent != 0) {
                                $openspots = 0;
                            }
                        }
                        if ($direction == 1) {
                            $movevalue = $i . "0";
                            $checklake = $pselect + $movevalue;
                            if ($checklake == 56 || $checklake == 46 || $checklake == 53 || $checklake == 43) {
                                $openspots = 0;
                            }
                            $temp1 = $loc . ($pselect + $movevalue);
                            $temp2 = $antiloc . ($pselect + $movevalue);
                            $openplayer = $gijoe[$temp1];
                            $openopponent = $gijoe[$temp2];
                            if ($openplayer != 0 || $openopponent != 0) {
                                $openspots = 0;
                            }
                        }
                    }
                    if ($openspots == 1) {
                        $piece1 = $gijoe[$loc . $pselect];
                        //attacker
                        $piece2 = $gijoe[$antiloc . $move];
                        //defender
                        if (attack_piece(abs($piece1), abs($piece2)) == 2) {
                            $startingspot = $loc . $pselect;
                            //start spot
                            $finishingspot = $loc . $move;
                            //finishing spot
                            $revealedpiece = "-" . abs($gijoe[$startingspot]);
                            // reveal the piece
                            $opponentsspot = $antiloc . $move;
                            // losers spot
                            $Attackname = number_to_name(abs($piece1));
                            // name of attackers piece
                            $Defendname = number_to_name(abs($piece2));
                            // name of defenders piece
                            $text = $attackersusername . "\\'s " . $Attackname . " (" . abs($piece1) . ") killed " . $defendersusername . "\\'s " . $Defendname . " (" . abs($piece2) . ")";
                            $piecelost = "p" . $loc . abs($piece2);
                            //piece captured
                            $newmovelist = move_list($pselect, $move, $gijoe['listofmoves'], $gijoe['posa'], $attackersusername, $defendersusername);
                            $db->query("UPDATE st_game SET listofmoves = '{$newmovelist}', {$piecelost} = {$piecelost} +1,{$startingspot} = 0, {$finishingspot} = {$revealedpiece}, {$opponentsspot} = 0, lastmove = {$move}, battletxt = '{$text}' WHERE st_room={$roomid}");
                            toggle_turn($roomid);
                        } else {
                            if (attack_piece(abs($piece1), abs($piece2)) == 1) {
                                $startingspot = $loc . $pselect;
                                $finishingspot = $antiloc . $move;
                                $piecesname = number_to_name(abs($piece1));
                                // name of the two pieces
                                $text = "Both " . $piecesname . "\\'s (" . abs($piece1) . ") were killed";
                                $piecelost = "p" . $loc . abs($piece2);
                                // piece captured
                                $piecelost2 = "p" . $antiloc . abs($piece1);
                                //piece lost
                                $newmovelist = move_list($pselect, $move, $gijoe['listofmoves'], $gijoe['posa'], $attackersusername, $defendersusername);
                                $db->query("UPDATE st_game SET listofmoves = '{$newmovelist}', {$piecelost} = {$piecelost} +1,{$piecelost2} = {$piecelost2} +1,{$startingspot} = 0, {$finishingspot} = 0, lastmove = {$move}, battletxt = '{$text}' WHERE st_room={$roomid}");
                                toggle_turn($roomid);
                            } else {
                                if (attack_piece(abs($piece1), abs($piece2)) == 3) {
                                    $winningpiece = number_to_name(abs($piece1));
                                    // name of the two pieces
                                    $text = $attackersusername . "\\'s " . $Attackname . "captured the flag";
                                    $newmovelist = move_list($pselect, $move, $gijoe['listofmoves'], $gijoe['posa'], $attackersusername, $defendersusername);
                                    $db->query("UPDATE st_game SET listofmoves = '{$newmovelist}', battletxt = '{$text}' WHERE st_room={$roomid}");
                                    award_win($roomid, $userid);
                                } else {
                                    $Attackname = number_to_name(abs($piece1));
                                    // name of attackers piece
                                    $Defendname = number_to_name(abs($piece2));
                                    // name of defenders piece
                                    $text = $attackersusername . "\\'s " . $Attackname . " (" . abs($piece1) . ") lost to " . $defendersusername . "\\'s " . $Defendname . " (" . abs($piece2) . ")";
                                    $startingspot = $loc . $pselect;
                                    $finishingspot = $antiloc . $move;
                                    $revealedpiece = "-" . abs($gijoe[$finishingspot]);
                                    $piecelost = "p" . $antiloc . abs($piece1);
                                    $newmovelist = move_list($pselect, $move, $gijoe['listofmoves'], $gijoe['posa'], $attackersusername, $defendersusername);
                                    $db->query("UPDATE st_game SET listofmoves = '{$newmovelist}', {$piecelost} = {$piecelost} +1,{$startingspot} = 0, {$finishingspot} = {$revealedpiece}, lastmove = {$move}, battletxt = '{$text}' WHERE st_room={$roomid}");
                                    toggle_turn($roomid);
                                }
                            }
                        }
                    }
                }
            } else {
                if ($gijoe[$loc . $move] == 0) {
                    $scoutresults = array();
                    $scoutresults = valid_scout($pselect, $move);
                    $differenceofspots = $scoutresults['distance'];
                    $direction = $scoutresults['direction'];
                    if ($differenceofspots > 0) {
                        $openspots = 1;
                        for ($i = 1; $i < $differenceofspots; $i++) {
                            if ($direction == 4) {
                                $checklake = $pselect + $i;
                                if ($checklake == 56 || $checklake == 46 || $checklake == 53 || $checklake == 43) {
                                    $openspots = 0;
                                }
                                $temp1 = $loc . ($pselect + $i);
                                $temp2 = $antiloc . ($pselect + $i);
                                $openplayer = $gijoe[$temp1];
                                $openopponent = $gijoe[$temp2];
                                if ($openplayer != 0 || $openopponent != 0) {
                                    $openspots = 0;
                                }
                            }
                            if ($direction == 3) {
                                $checklake = $pselect - $i;
                                if ($checklake == 56 || $checklake == 46 || $checklake == 53 || $checklake == 43) {
                                    $openspots = 0;
                                }
                                $temp1 = $loc . ($pselect - $i);
                                $temp2 = $antiloc . ($pselect - $i);
                                $openplayer = $gijoe[$temp1];
                                $openopponent = $gijoe[$temp2];
                                if ($openplayer != 0 || $openopponent != 0) {
                                    $openspots = 0;
                                }
                            }
                            if ($direction == 2) {
                                $movevalue = $i . "0";
                                $checklake = $pselect - $movevalue;
                                if ($checklake == 56 || $checklake == 46 || $checklake == 53 || $checklake == 43) {
                                    $openspots = 0;
                                }
                                $temp1 = $loc . ($pselect - $movevalue);
                                $temp2 = $antiloc . ($pselect - $movevalue);
                                $openplayer = $gijoe[$temp1];
                                $openopponent = $gijoe[$temp2];
                                if ($openplayer != 0 || $openopponent != 0) {
                                    $openspots = 0;
                                }
                            }
                            if ($direction == 1) {
                                $movevalue = $i . "0";
                                $checklake = $pselect - $movevalue;
                                if ($checklake == 56 || $checklake == 46 || $checklake == 53 || $checklake == 43) {
                                    $openspots = 0;
                                }
                                $temp1 = $loc . ($pselect + $movevalue);
                                $temp2 = $antiloc . ($pselect + $movevalue);
                                $openplayer = $gijoe[$temp1];
                                $openopponent = $gijoe[$temp2];
                                if ($openplayer != 0 || $openopponent != 0) {
                                    $openspots = 0;
                                }
                            }
                        }
                        if ($openspots == 1) {
                            $startingspot = $loc . $pselect;
                            $finishingspot = $loc . $move;
                            $piecetomove = $gijoe[$startingspot];
                            $text = "";
                            $newmovelist = move_list($pselect, $move, $gijoe['listofmoves'], $gijoe['posa'], $attackersusername, $defendersusername);
                            $db->query("UPDATE st_game SET listofmoves = '{$newmovelist}', {$startingspot} = 0, {$finishingspot} = {$piecetomove}, pselected = 0, lastmove = {$move}, battletxt = '{$text}' WHERE st_room={$roomid}");
                            toggle_turn($roomid);
                        }
                    }
                }
            }
        }
    }
}