<commit_before>// Sets up the game board as a 5x5 two-dimensional array.
var board = new Array(8);
for (x = 0; x < board.length; x++) {
    board[x] = new Array(6);
};
var locationX;
var locationY;
var maxX = 7;
var maxY = 5;

var main = function() {
    
};

function rowEdge(x) {
    if (x > maxX) return 0;
    if (x < 0) return maxX;
};

function colEdge(y) {
    if (y > maxY) return 0;
    if (y < 0) return maxY;
};

// Assigns a random square the wumpus code "9"
function placeWumpus() {
    tempX = Math.floor(Math.random() * (maxX + 1));
    tempY = Math.floor(Math.random() * (maxY + 1));
    board[tempX][tempY] = 9;
    board[rowEdge(tempX + 1)][tempY] = 7;
    board[rowEdge(tempX - 1)][tempY] = 7;
    board[tempX][colEdge(tempY + 1)] = 7;
    board[tempX][colEdge(tempY - 1)] = 7;
};

// Assigns a random square the player code "8".  Ensures it is not the same square as the wumpus through recursion.
function placePlayer() {
    locationX = Math.floor((Math.random() * (maxX + 1)));
    locationY = Math.floor((Math.random() * (maxY + 1)));
    if (board[locationX][locationY] == 9) {
        placePlayer();
    }
    else {
        board[locationX][locationY] = 8;
    }
};

// Clears the game board.
function resetGame() {
    for (x = 0; x < board.length; x++) {
        for (y = 0; y < board[x].length; y ++) {
            board[x][y] = 0;
            $("#0" + x.toString() + "0" + y.toString()).removeClass("wumpus");
            $("#0" + x.toString() + "0" + y.toString()).removeClass("player");
            $("#0" + x.toString() + "0" + y.toString()).removeClass("near-wumpus");
        }
    }
};

// Places all elements ont the board using jQuery.
function drawBoard() {
    
    // Nested for loops check through every cell of board.
    for (x = 0; x < board.length; x++) {
        var outputL = "";
        for (y = 0; y < board[x].length; y ++) {
            // If square contains player, apply "player" css.
            if (board[x][y] == 8) {
                $("#0" + x.toString() + "0" + y.toString()).addClass("player");
            };
        };
    };
};

$("#reset").click(function() {
    gameTester();
});

function movePlayer(x, y) {
    $("#0" + locationX.toString() + "0" + locationY.toString()).removeClass("player");
    if (x == 0) {
        moveY(y);
    }
    if (y == 0) {
        moveX(x);
    }
    $("#0" + locationX.toString() + "0" + locationY.toString()).addClass("player");
    checkLocation();
};

function checkLocation() {
    if (board[locationX][locationY] == 7) 
        $("#0" + locationX.toString() + "0" + locationY.toString()).addClass("near-wumpus");
    if (board[locationX][locationY] == 9) 
        $("#0" + locationX.toString() + "0" + locationY.toString()).addClass("wumpus");
};

function moveX (x) {
    if ((locationX + x) == -1) {
        locationX = 4;
    }
    else if ((locationX + x) == (maxX + 1)) {
        locationX = 0;
    }
    else {
        locationX += x;
    }
};

function moveY (y) {
    if ((locationY + y) == -1) {
        locationY = 4;
    }
    else if ((locationY + y) == (maxY + 1)) {
        locationY = 0;
    }
    else {
        locationY += y;
    }
};

$(document).keypress(function(e) {
    
    // Move player left
    if (e.which == 97) {
        movePlayer(-1, 0);
    }
    
    // Move player up
    if(e.which == 119) {
        movePlayer(0, -1);
    }
    
    // Move player right
    if(e.which == 100) {
        movePlayer(1, 0);
    }
    
    // Move player down
    if(e.which == 115) {
        movePlayer(0, 1);
    }<commit_msg>fixes for movement<commit_after>// Sets up the game board as a 5x5 two-dimensional array.
var locationX;
var locationY;
var maxX = 7;
var maxY = 5;

var board = new Array(maxX + 1);
for (x = 0; x < board.length; x++) {
    board[x] = new Array(maxY + 1);
};

var main = function() {
    
};

function rowEdge(x) {
    if (x > (maxX)) return 0;
    else if (x < 0) return maxX;
    else return x;
};

function colEdge(y) {
    if (y > (maxY)) return 0;
    else if (y < 0) return maxY;
    else return y;
};

// Assigns a random square the wumpus code "9"
function placeWumpus() {
    tempX = Math.floor(Math.random() * (maxX + 1));
    tempY = Math.floor(Math.random() * (maxY + 1));
    board[tempX][tempY] = 9;
    board[rowEdge(tempX + 1)][tempY] = 7;
    board[rowEdge(tempX - 1)][tempY] = 7;
    board[tempX][colEdge(tempY + 1)] = 7;
    board[tempX][colEdge(tempY - 1)] = 7;
};

// Assigns a random square the player code "8".  Ensures it is not the same square as the wumpus through recursion.
function placePlayer() {
    locationX = Math.floor((Math.random() * (maxX + 1)));
    locationY = Math.floor((Math.random() * (maxY + 1)));
    if (board[locationX][locationY] == 9) {
        placePlayer();
    }
    else {
        board[locationX][locationY] = 8;
    }
};

// Clears the game board.
function resetGame() {
    for (x = 0; x < board.length; x++) {
        for (y = 0; y < board[x].length; y ++) {
            board[x][y] = 0;
            $("#0" + x.toString() + "0" + y.toString()).removeClass("wumpus");
            $("#0" + x.toString() + "0" + y.toString()).removeClass("player");
            $("#0" + x.toString() + "0" + y.toString()).removeClass("near-wumpus");
        }
    }
};

// Places all elements ont the board using jQuery.
function drawBoard() {
    
    // Nested for loops check through every cell of board.
    for (x = 0; x < board.length; x++) {
        var outputL = "";
        for (y = 0; y < board[x].length; y ++) {
            // If square contains player, apply "player" css.
            if (board[x][y] == 8) {
                $("#0" + x.toString() + "0" + y.toString()).addClass("player");
            };
        };
    };
};

$("#reset").click(function() {
    gameTester();
});

function movePlayer(x, y) {
    $("#0" + locationX.toString() + "0" + locationY.toString()).removeClass("player");
    if (x == 0) {
        moveY(y);
    }
    if (y == 0) {
        moveX(x);
    }
    $("#0" + locationX.toString() + "0" + locationY.toString()).addClass("player");
    checkLocation();
};

function checkLocation() {
    if (board[locationX][locationY] == 7) 
        $("#0" + locationX.toString() + "0" + locationY.toString()).addClass("near-wumpus");
    if (board[locationX][locationY] == 9) 
        $("#0" + locationX.toString() + "0" + locationY.toString()).addClass("wumpus");
};

function moveX (x) {
    if ((locationX + x) < 0) {
        locationX = (board.length - 1);
    }
    else if ((locationX + x) > (maxX)) {
        locationX = 0;
    }
    else {
        locationX += x;
    }
};

function moveY (y) {
    if ((locationY + y) < 0) {
        locationY = (board[0].length - 1);
    }
    else if ((locationY + y) > (maxY)) {
        locationY = 0;
    }
    else {
        locationY += y;
    }
};

$(document).keypress(function(e) {
    
    // Move player left
    if (e.which == 97) {
        movePlayer(-1, 0);
    }
    
    // Move player up
    if(e.which == 119) {
        movePlayer(0, -1);
    }
    
    // Move player right
    if(e.which == 100) {
        movePlayer(1, 0);
    }
    
    // Move player down
    if(e.which == 115) {
        movePlayer(0, 1);
    }
{'fraction_non_alphanumeric': 0.19129709439733072, 'fraction_numerical': 0.022382872236896983, 'mean_word_length': 2.203027604630454, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3648837', 'n_tokens_mistral': 2645, 'n_tokens_neox': 2547, 'n_words': 646}