<commit_before>import Effect from '../effect';

export class SinkEffect extends Effect {
    constructor(subject, callback) {
        super(subject, 30);
        this.callback = callback;
        subject.offset = 0;
        this.destroyed = false;
    }

    step() {
        this.subject.offset ++;
    }

    finish() {
        this.callback();
    }
}

export default class Ship {
    constructor(state) {
        this.state = state;
        this.animationStep = 0;
        this.alive = true;
        this.nextDirection = null;
        this.offset = 0;
    }

    draw(screen) {
        this.parts.map((part) => {
            part.draw(screen, this.animationStep, this.offset);
        });
    }

    move(onlyFirst = false, notFirst = false) {
        if (this.nextDirection) {
            this.direction = this.nextDirection;
            this.nextDirection = null;
        }

        let next = !this.parts[0].next ? null : {
            x: this.parts[0].next.x + this.direction.x,
            y: this.parts[0].next.y + this.direction.y
        };

        this.parts.some((part) => {
            part.previous = part.position;
            part.position = part.next;
            part.next = next;
            part.paused = false;
            next = part.position;

            return onlyFirst;
        });

        if (onlyFirst) {
            let first = true;
            this.parts.forEach((part) => {
                part.paused = !first;
                first = false;
            });
        }
    }

    addOccupied(occupied) {
        occupied.push(this.parts[0].position);
        for (const part of this.parts) {
            if (part.previous) {
                occupied.push(part.previous);
            }
        }
    }

    collidesWith(ship) {
        if (!this.parts[0] || !this.parts[0].next) {
            return false;
        }

        return ship.parts.some((part) => {
            return part.position.x == this.parts[0].next.x && part.position.y == this.parts[0].next.y;
        });
    }
}<commit_msg>fix collision with traders<commit_after>import Effect from '../effect';

export class SinkEffect extends Effect {
    constructor(subject, callback) {
        super(subject, 30);
        this.callback = callback;
        subject.offset = 0;
        this.destroyed = false;
    }

    step() {
        this.subject.offset ++;
    }

    finish() {
        this.callback();
    }
}

export default class Ship {
    constructor(state) {
        this.state = state;
        this.animationStep = 0;
        this.alive = true;
        this.nextDirection = null;
        this.offset = 0;
    }

    draw(screen) {
        this.parts.map((part) => {
            part.draw(screen, this.animationStep, this.offset);
        });
    }

    move(onlyFirst = false, notFirst = false) {
        if (this.nextDirection) {
            this.direction = this.nextDirection;
            this.nextDirection = null;
        }

        let next = !this.parts[0].next ? null : {
            x: this.parts[0].next.x + this.direction.x,
            y: this.parts[0].next.y + this.direction.y
        };

        this.parts.some((part) => {
            part.previous = part.position;
            part.position = part.next;
            part.next = next;
            part.paused = false;
            next = part.position;

            return onlyFirst;
        });

        if (onlyFirst) {
            let first = true;
            this.parts.forEach((part) => {
                part.paused = !first;
                first = false;
            });
        }
    }

    addOccupied(occupied) {
        for (const part of this.parts) {
            if (part.next) {
                occupied.push(part.next);
            }
        }
    }

    collidesWith(ship) {
        if (!this.parts[0] || !this.parts[0].next) {
            return false;
        }

        return ship.parts.some((part) => {
            return part.position.x == this.parts[0].next.x && part.position.y == this.parts[0].next.y;
        });
    }
}
{'fraction_non_alphanumeric': 0.13233830845771144, 'fraction_numerical': 0.006218905472636816, 'mean_word_length': 1.4759852216748768, 'pattern_counts': {'":': 0, '<': 3, '<?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': '6299960', 'n_tokens_mistral': 1208, 'n_tokens_neox': 1162, 'n_words': 220}