◀ 돌아가기 (Main)

💡 Strategy Examples

복사해서 사용할 수 있는 전략 예제들입니다.

🎯 Basic Sniper (기본 저격)

가장 가까운 적을 찾아 계속 공격합니다.

*run() {
    while(true) {
        // onScan에서 저장한 타겟이 있는지 확인
        if (this.target) {
            // 조준
            this.turnGunTo(this.target.aimAngle);
            
            // 발사 (거리가 가까우면)
            if (this.target.dist < 300) {
                this.fire('A');
            } else {
                this.moveForward(30); // 접근
            }
            
            // 타겟 정보 초기화 (다음 스캔 대기)
            this.target = null;
        } else {
            // 적을 찾기 위해 제자리 회전
            this.turnRight(10);
        }
    }
}

onScan(enemies) {
    // 가장 가까운 적 저장
    this.target = enemies[0];
}

🛡️ Hit & Run (치고 빠지기)

공격 후 안전하게 후퇴합니다.

*run() {
    while(true) {
        if (this.target) {
            // 1. 발사
            this.turnGunTo(this.target.aimAngle);
            this.fire('B');
            
            // 2. 후퇴 (회피)
            this.moveBackward(50);
            this.turnRight(45);
            this.moveForward(50);
            
            this.target = null;
        } else {
            this.turnGunRight(20); // 레이더 회전
            this.wait(5);
        }
    }
}

onScan(enemies) {
    this.target = enemies[0];
}

🔁 Square Patrol (사각형 순찰)

일정한 구역을 순찰합니다.

*run() {
    while(true) {
        for(let i=0; i<4; i++) {
            this.moveForward(150);
            this.turnRight(90);
            // 순찰 중에도 적을 만나면 쏘는 로직 추가 가능
        }
    }
}