<commit_before>package jdungeonquest;

import jdungeonquest.enums.EntryDirection;
import jdungeonquest.enums.RoomWallType;

public class GameMap {
    public final static int MAX_X = 10;
    public final static int MAX_Y = 13;

    private Tile[][] tiles =  new Tile[10][13];
    
    public GameMap(){
        
    }
   
    public void setTile(int x, int y, Tile tile) {
        tiles[x][y] = tile;
    }

    public Tile getTile(int x, int y) {
        return tiles[x][y];
    }

    public Tile[][] getTiles(){
        return tiles;
    }
    
    /**
     * 
     * @param x
     * @param y
     * @return 
     */
    public boolean isFree(int x, int y) {
        if (tiles[x][y] == null) {
            return true;
        }
        return false;
    }

    public boolean isAdjacent(Position p1, Position p2){
        if(p1 == p2){
            return false;
        }
        if( (p1.getX() == p2.getX()) && (Math.abs( p1.getY() - p2.getY()) == 1)){
            return true;
        }
        if( (p1.getY() == p2.getY()) && (Math.abs( p1.getX() - p2.getX()) == 1)){
            return true;
        }
        return false;
    }
    
    public boolean canMoveFrom(Position p1, Position p2){
        //U[0] L[1] D[2] R[3]
        if( p1.getY() == p2.getY()){ //same column
            if(p1.getX() > p2.getX()){ //going left
                if(getTile(p1.getX(), p1.getY()).getWalls().get(1) != RoomWallType.WALL){
                    return true;
                }
            }
            if(p1.getX() < p2.getX()){ //going right
                if(getTile(p1.getX(), p1.getY()).getWalls().get(3) != RoomWallType.WALL){
                    return true;
                }
            }
            return false;
        }
        if( p1.getX() == p2.getX()){ //same row
            if(p1.getY() > p2.getY()){ //going up
                if(getTile(p1.getX(), p1.getY()).getWalls().get(0) != RoomWallType.WALL){
                    return true;
                }
            }
            if(p1.getY() < p2.getY()){ //going down
                if(getTile(p1.getX(), p1.getY()).getWalls().get(2) != RoomWallType.WALL){
                    return true;
                }
            }
            return false;
        }    
        return false;
    }

    public boolean canMoveTo(Position p1, Position p2){
        return canMoveFrom(p2, p1);
    }    
    
    /**
     * @param playerPos
     * @param tilePos
     * @param tile
     * @return number of rotations needed to place tile correctly.
     */
    public int getRequiredRotation(Position playerPos, Position tilePos, Tile tile) {
        //U[0] L[1] D[2] R[3]
        EntryDirection direction = null;
        if( playerPos.getY() == tilePos.getY()){ //same column
            if(playerPos.getX() > tilePos.getX()){ //going right
                direction = EntryDirection.RIGHT;
            }
            if(playerPos.getX() < tilePos.getX()){ //going left
                direction = EntryDirection.LEFT;
            }
        }
        if( playerPos.getX() == tilePos.getX()){ //same row
            if(playerPos.getY() > tilePos.getY()){ //going down
                direction = EntryDirection.DOWN;
            }
            if(playerPos.getY() < tilePos.getY()){ //going up
                direction = EntryDirection.UP;
            }
        }
        
        int turns = 0;
        
        Tile dummy = new Tile(tile);
        while(dummy.getEntryDirection() != direction){
            turns++;
            dummy.rotate(1);<commit_msg>Switched to overloaded function and changed comments in GameMap<commit_after>package jdungeonquest;

import jdungeonquest.enums.EntryDirection;
import jdungeonquest.enums.RoomWallType;

public class GameMap {
    public final static int MAX_X = 10;
    public final static int MAX_Y = 13;

    private Tile[][] tiles =  new Tile[10][13];
    
    public GameMap(){
        
    }
   
    public void setTile(int x, int y, Tile tile) {
        tiles[x][y] = tile;
    }

    public Tile getTile(int x, int y) {
        return tiles[x][y];
    }

    public Tile[][] getTiles(){
        return tiles;
    }
    
    /**
     * 
     * @param x
     * @param y
     * @return 
     */
    public boolean isFree(int x, int y) {
        if (tiles[x][y] == null) {
            return true;
        }
        return false;
    }

    public boolean isAdjacent(Position p1, Position p2){
        if(p1 == p2){
            return false;
        }
        if( (p1.getX() == p2.getX()) && (Math.abs( p1.getY() - p2.getY()) == 1)){
            return true;
        }
        if( (p1.getY() == p2.getY()) && (Math.abs( p1.getX() - p2.getX()) == 1)){
            return true;
        }
        return false;
    }
    
    public boolean canMoveFrom(Position p1, Position p2){
        //U[0] L[1] D[2] R[3]
        if( p1.getY() == p2.getY()){ //same column
            if(p1.getX() > p2.getX()){ //going left
                if(getTile(p1).getWalls().get(1) != RoomWallType.WALL){
                    return true;
                }
            }
            if(p1.getX() < p2.getX()){ //going right
                if(getTile(p1).getWalls().get(3) != RoomWallType.WALL){
                    return true;
                }
            }
            return false;
        }
        if( p1.getX() == p2.getX()){ //same row
            if(p1.getY() > p2.getY()){ //going up
                if(getTile(p1).getWalls().get(0) != RoomWallType.WALL){
                    return true;
                }
            }
            if(p1.getY() < p2.getY()){ //going down
                if(getTile(p1).getWalls().get(2) != RoomWallType.WALL){
                    return true;
                }
            }
            return false;
        }
        return false;
    }

    public boolean canMoveTo(Position p1, Position p2){
        return canMoveFrom(p2, p1);
    }    
    
    /**
     * @param playerPos
     * @param tilePos
     * @param tile
     * @return number of rotations needed to place tile correctly.
     */
    public int getRequiredRotation(Position playerPos, Position tilePos, Tile tile) {
        //U[0] L[1] D[2] R[3]
        EntryDirection direction = null;
        if( playerPos.getY() == tilePos.getY()){ //same column
            if(playerPos.getX() > tilePos.getX()){ //going left, make sure entry is on the right
                direction = EntryDirection.RIGHT;
            }
            if(playerPos.getX() < tilePos.getX()){ //going right
                direction = EntryDirection.LEFT;
            }
        }
        if( playerPos.getX() == tilePos.getX()){ //same row
            if(playerPos.getY() > tilePos.getY()){ //going up
                direction = EntryDirection.DOWN;
            }
            if(playerPos.getY() < tilePos.getY()){ //going down
                direction = EntryDirection.UP;
            }
        }
        
        int turns = 0;
        
        Tile dummy = new Tile(tile);
        while(dummy.getEntryDirection() != direction){
            turns++;
            dummy.rotate(1);
{'fraction_non_alphanumeric': 0.1401789518534299, 'fraction_numerical': 0.017043033659991477, 'mean_word_length': 1.4691444600280505, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, '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': '3940935', 'n_tokens_mistral': 2293, 'n_tokens_neox': 2228, 'n_words': 500}