<commit_before><html>
<head>
    <script src="https://cdn.jsdelivr.net/vue/latest/vue.js"></script>
</head>
<style>
    #app { margin: 50px 0px 0px 50px; }
    *:focus {
        outline: none;
    }
    .ticbox {
        display:block; width:45px; height:45px; margin:5px; float:left; background-color:#efefef;
        font-size:45px; line-height: 45px; text-align: center; vertical-align: middle;
    }
</style>
<body>

<div id="app" tabindex="0"
     v-on:keydown.up="movePlayer(0,-1)"
     v-on:keydown.down="movePlayer(0,1)"
     v-on:keydown.left="movePlayer(-1,0)"
     v-on:keydown.right="movePlayer(1,0)"
     v-on:keydown.space="movePlayer(0,0)"
        >
    <div v-for="(rowIdx, row) in board" style="width:600px;">
        <div v-for="(colIdx, item) in row">
            <span class="ticbox" >{{ item.val || ' ' }}</span>
        </div>
    </div>
</div>

<script>
    var vm = new Vue({
        el: '#app',
        data: {
            roomSize: 10,
            board: [],
            player: {
                x: 1,
                y: 1,
                char: '@'
            },
            obstacles: [],
            monsters: []
            
        },
        methods: {
            movePlayer: function(x,y){
                var newX = this.player.x + x;
                var newY = this.player.y + y;
                if(newX >= 0 && newX < this.board[0].length 
                   && newY >= 0  && newY < this.board.length
                   && this.obstacles[newX][newY] != 1){
                       if(this.monsters[newX][newY] != null){
                           this.monsters[newX][newY] = this.hitMonster(this.monsters[newX][newY]);
                       } else {
                           this.player.x = newX;
                           this.player.y = newY;
                       }
                }
                
                
                this.board = this.displayBoard();
            },
            blankBoard: function(){
                var b = new Array(this.roomSize);
                for (var i = 0; i < this.roomSize; i++) {
                    b[i] = new Array(this.roomSize);
                    for(var j = 0; j < this.roomSize; j++){
                        b[i][j] = null;
                    }
                }
                return b;
            },
            displayBoard: function(){
                var board = this.blankBoard();
                
                for (var i = 0; i < board.length; i++) {
                    for (var j = 0; j < board[i].length; j++) {
                        var val = null;
                        if (this.obstacles[i][j] != null) {
                            val = this.obstacles[i][j];
                        }

                        if (this.monsters[i][j] != null) {
                            val = this.monsters[i][j];
                        }
                        
                        // Always write a value for each space in the board, use null if no other thing
                        board[j].$set(i, {val: val});
                    }
                }

                board[this.player.y].$set(this.player.x, {val: this.player.char});
                return board;
            },
            initBoard: function(){
                this.board = this.blankBoard();
                this.obstacles = this.blankBoard();
                this.obstacles[2][7] = '0';
                this.obstacles[8][1] = '0';
                this.monsters = this.blankBoard();
                this.monsters[1][5] = 'c';
            },
            hitMonster: function(monster){
                monster = monster.charCodeAt(0) - 96; // Convert to int
                monster--; // Decrement;
                monster = (monster <= 0) ? null : String.fromCharCode(96 + monster); // Either null if dead or next letter down
                return monster;
            }
        }
    });
    
    vm.initBoard();
    vm.board = vm.displayBoard();
    

</script><commit_msg>Moving and hitting monsters<commit_after><html>
<head>
    <script src="https://cdn.jsdelivr.net/vue/latest/vue.js"></script>
</head>
<style>
    #app { margin: 50px 0px 0px 50px; }
    *:focus {
        outline: none;
    }
    .ticbox {
        display:block; width:45px; height:45px; margin:5px; float:left; background-color:#efefef;
        font-size:45px; line-height: 45px; text-align: center; vertical-align: middle;
    }
</style>
<body>

<div id="app" tabindex="0"
     v-on:keydown.up="movePlayer(0,-1)"
     v-on:keydown.down="movePlayer(0,1)"
     v-on:keydown.left="movePlayer(-1,0)"
     v-on:keydown.right="movePlayer(1,0)"
     v-on:keydown.space="movePlayer(0,0)"
        >
    <div v-for="(rowIdx, row) in board" style="width:600px;">
        <div v-for="(colIdx, item) in row">
            <span class="ticbox" >{{ item.val || ' ' }}</span>
        </div>
    </div>
    <div>
        Health: {{player.health}}
    </div>
</div>

<script>
    var vm = new Vue({
        el: '#app',
        data: {
            roomSize: 10,
            board: [],
            player: {
                x: 1,
                y: 1,
                char: '@',
                health: 5
            },
            obstacles: [],
            monsters: []
            
        },
        methods: {
            movePlayer: function(x,y){
                var newX = this.player.x + x;
                var newY = this.player.y + y;
                if(newX >= 0 && newX < this.board[0].length 
                   && newY >= 0  && newY < this.board.length
                   && this.obstacles[newX][newY] == null){
                       if(this.monsters[newX][newY] != null){
                           this.monsters[newX][newY] = this.hitMonster(this.monsters[newX][newY]);
                       } else {
                           this.player.x = newX;
                           this.player.y = newY;
                       }
                }

                this.runTurn();
                this.board = this.displayBoard();
                
                
            },
            blankBoard: function(){
                var b = new Array(this.roomSize);
                for (var i = 0; i < this.roomSize; i++) {
                    b[i] = new Array(this.roomSize);
                    for(var j = 0; j < this.roomSize; j++){
                        b[i][j] = null;
                    }
                }
                return b;
            },
            displayBoard: function(){
                var board = this.blankBoard();
                
                for (var i = 0; i < board.length; i++) {
                    for (var j = 0; j < board[i].length; j++) {
                        var val = null;
                        if (this.obstacles[i][j] != null) {
                            val = this.obstacles[i][j];
                        }

                        if (this.monsters[i][j] != null) {
                            val = this.monsters[i][j];
                        }
                        
                        // Always write a value for each space in the board, use null if no other thing
                        board[j].$set(i, {val: val});
                    }
                }

                board[this.player.y].$set(this.player.x, {val: this.player.char});
                return board;
            },
            initBoard: function(){
                this.board = this.blankBoard();
                this.obstacles = this.blankBoard();
                this.obstacles[2][7] = '0';
                this.obstacles[8][1] = '0';
                this.monsters = this.blankBoard();
                this.monsters[1][5] = 'c';
                this.monsters[5][1] = 'c';
            },
            hitMonster: function(monster){
                monster = monster.charCodeAt(0) - 96; // Convert to int
                monster--; // Decrement;
                monster = (monster <= 0) ? null : String.fromCharCode(96 + monster); // Either null if dead or next letter down
                return monster;
            },
            hitPlayer: function(){
                this.player.health--;
            },
            runTurn: function(){
                var movedMonsters = this.blankBoard();
                // Move each monster towards the player
                for (var i = 0; i < this.board.length; i++) {
                    for (var j = 0; j < this.board[i].length; j++) {
                        if (this.monsters[i][j] != null) {
                            var tX = i, tY = j;
                            if(this.player.x > i && this.obstacles[i+1][j] == null){ tX = i+1; tY = j; }
                            if(this.player.x < i && this.obstacles[i-1][j] == null){ tX = i-1; tY = j; }
                            if(this.player.y > j && this.obstacles[i][j+1] == null){ tX = i; tY = j+1; }
                            if(this.player.y < j && this.obstacles[i][j-1] == null){ tX = i; tY = j-1; }
                            
                            if(this.player.x == tX && this.player.y == tY){
                                this.hitPlayer();
                                tX = i; tY = j;
                            }

                            if(movedMonsters[tX][tY] != null) {
                                tX = i; tY = j;
                            }

                            movedMonsters[tX][tY] = this.monsters[i][j];
                        }
                    }
                }
                this.monsters = movedMonsters;
            }
        }
    });
    
    vm.initBoard();
    vm.board = vm.displayBoard();
    

</script>
{'fraction_non_alphanumeric': 0.14136671883150756, 'fraction_numerical': 0.012728221178925404, 'mean_word_length': 1.0686232196806216, 'pattern_counts': {'":': 0, '<': 59, '<?xml version=': 0, '>': 47, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '938754', 'n_tokens_mistral': 2931, 'n_tokens_neox': 2750, 'n_words': 566}