Codingame『Hostage Rescue - Part 1 - Training』

黄金バット 第2巻


 バットマンがピョンピョンしながら爆弾を探すゲーム。
あぁ^~バットマンがぴょんぴょんするんじゃぁ^~
1マスずつ動いてたら到底間に合わないので、移動可能範囲を1/2にしながら動く。


 動いてるのはこんな感じになる。
http://www.codingame.com/replay/solo/26625693


using System;
using System.Linq;
using System.IO;
using System.Text;
using System.Collections;
using System.Collections.Generic;

/**
 * Auto-generated code below aims at helping you parse
 * the standard input according to the problem statement.
 **/
class Player
{
    static void Main(string[] args)
    {
        string[] dir = {"U","D","R","L"};
        
        string[] inputs;
        inputs = Console.ReadLine().Split(' ');
        int W = int.Parse(inputs[0]); // width of the building.
        int H = int.Parse(inputs[1]); // height of the building.
        int N = int.Parse(Console.ReadLine()); // maximum number of turns before game over.
        inputs = Console.ReadLine().Split(' ');
        int X = int.Parse(inputs[0]);
        int Y = int.Parse(inputs[1]);
        int[] xr = {0,W}; //X方向の移動可能範囲
        int[] yr = {0,H}; //Y方向の移動可能範囲
        
        Console.Error.WriteLine("W:"+W);
        Console.Error.WriteLine("H:"+H);
        Console.Error.WriteLine("N:"+N);

        // game loop
        while (true)
        {
            string BOMB_DIR = Console.ReadLine(); // the direction of the bombs from batman's current location (U, UR, R, DR, D, DL, L or UL)

            // Write an action using Console.WriteLine()
            // To debug: Console.Error.WriteLine("Debug messages...");
            Console.Error.WriteLine("OX0 OY0:{0} {1}",xr[0],yr[0]);
            Console.Error.WriteLine("OX1 OY1:{0} {1}",xr[1],yr[1]);
            Console.Error.WriteLine("X Y:{0} {1}",X,Y);
            Console.Error.WriteLine(BOMB_DIR);
            
            for(int i = 0; i < 4; i++ ) {
                if(BOMB_DIR.IndexOf(dir[i]) != -1) { //方向指示にUDLRが含まれてるかチェック
                    switch(dir[i]) {
                        case "U": //上方向指示
                            yr[1] = Y;
                            Y = (int)((yr[0] + Y) * 0.5);
                            break;
                        case "D": //下方向指示
                            yr[0] = Y;
                            Y = (int)((yr[1] + Y) * 0.5);
                            break;
                        case "R": //右方向指示
                            xr[0] = X;
                            X = (int)((xr[1]+X) * 0.5);
                            break;
                        case "L": //左方向指示
                            xr[1] = X;
                            X = (int)((xr[0]+X) * 0.5);
                            break;
                    }
                }
            }
            
            Console.WriteLine("{0} {1}",X,Y); // the location of the next window Batman should jump to.
            
        }
    }
}


ダークナイト ライジング [DVD]