<?php

include("functions.php");
session_start();
if (isset($_POST["snapshot"])) {
    setModules();
    if($_POST["snapshot"] === "3"){
        unlink(realpath("./Game/") . "/LoadSavedGame");
        copy(realpath("./Game/") . "/LastState", realpath("./Game/") . "/LoadSavedGame");
        endScript("turn.php");
    }
    if($_POST["snapshot"] === "2")
    {
        $r_file = fopen(realpath("./Game/") . "/LoadSavedGame", 'r');
    }else{
        //$r_file = fopen("./Game/LastState", 'r');
        endScript("shuffle.php");
    }
    $initially_file = fopen(realpath("./Game/") . "/initially", 'w');
    fputs($initially_file, "initially:\n");
    $str = "";
    $str = fgets($r_file);
    while ($str != FALSE) {
        fwrite($initially_file, $str);
        $str = fgets($r_file);
    }
    fclose($initially_file);
    fclose($r_file);
    UpdateGameplan();
    endScript("turn.php");
}
?>
