Shadows of the Knight - Episode 1 - Puzzle discussion

I succed to do one action every turn but my character did this again. He moves in RD then in D and he started again!!! :confused:

i need help with the shadows of the knight

i cant get past tower because there is invalid input. how do i fix this? is there a way to do this without using the bisection method? (my coding language is python)

i cant get past tower because there is invalid input. how do i fix this? is there a way to do this without using the bisection method? (my coding language is python)
[/quote]

help!! what is wrong with my code? All of test cases are pass,but the submit result is 85%,not 100%.

import sys
import math

w, h = [int(i) for i in input().split()]
n = int(input())  # maximum number of turns before game over.
x0, y0 = [int(i) for i in input().split()]


xw = w - x0
yh = h - y0

x1 = x0
y1 = y0

s = []

while True:
    bomb_dir = input()  # the direction of the bombs from batman's current location (U, UR, R, DR, D, DL, L or UL)

   
s.append(bomb_dir)

if len(s)==1:            
    
    if s[0]=='U':
        y = y1
    if s[0]=='D':
        y = yh
    if s[0]=='L':
        x = x1
    if s[0]=='R':
        x = xw
    if s[0]=='UR':
        y = y1
        x = xw
    if s[0]=='UL':
        y = y1
        x = x1
    if s[0]=='DR':
        y = yh
        x = xw
    if s[0]=='DL':
        y = yh
        x = x1
      
     
if bomb_dir == 'U':      
    if y>=2:    
        y = (y//2)
    else:
        y=1
    y0 = y0-y
         
elif bomb_dir == 'UR':
    if x>=2 and y>=2:
        x = (x//2)
        y = (y//2)      
    elif x>=2 and y<2:
        x = (x//2)
        y = 1
    elif x<2 and y>=2:
        x = 1
        y = (y//2)
    elif x<2 and y<2:
        x = 1
        y = 1
    
    x0 = (x0+x)
    y0 = (y0-y)
    
elif bomb_dir == 'R':               
    if x>=2:
        x = (x//2)
    else:
        x = 1
    
    x0 = (x0+x)
    
    
elif bomb_dir == 'DR':
    if x>=2 and y>=2:
        x = (x//2)
        y = (y//2)      
    elif x>=2 and y<2:
        x = (x//2)
        y = 1
    elif x<2 and y>=2:
        x = 1
        y = (y//2)
    elif x<2 and y<2:
        x = 1
        y = 1
        
    x0 = (x0+x)
    y0 = (y0+y)

elif bomb_dir == 'D':  
    if y>=2:
        y = (y//2)
    else:
        y = 1
    
    y0 = y0+y
    
elif bomb_dir == 'DL':
    if x>=2 and y>=2:
        x = (x//2)
        y = (y//2)      
    elif x>=2 and y<2:
        x = (x//2)
        y = 1
    elif x<2 and y>=2:
        x = 1
        y = (y//2)
    elif x<2 and y<2:
        x = 1
        y = 1

    x0 = x0-x
    y0 = y0+y
    
elif bomb_dir == 'L':
    
    if x>=2:
        x = (x//2)
    else:
        x = 1
    x0 = (x0-x)
    
    
elif bomb_dir == 'UL':
    
    if x>=2 and y>=2:
        x = (x//2)+1
        y = (y//2)+1     
    elif x>=2 and y<2:
        x = (x//2)+1
        y = 1
    elif x<2 and y>=2:
        x = 1
        y = (y//2)
    elif x<2 and y<2:
        x = 1
        y = 1

    x0 = (x0-x)
    y0 = (y0-y)

       
print(x0, y0)

can you explain what you tried to implement? Itā€™s fairly difficult to read that kind of program with repetitive chunks and unnamed variables.

Hello, can anynoe help me understand why we dont go to the bomb at the first time. And what does h means with infinitve loop?

i havent complete any task like this again can anyne help me please

i am stuck at ā€˜Evasiveā€™ stage at round 6 ($N=0~6).
The red circle(or target) at this mode would be varient, but i donā€™t get the answer at round 6.

why I see this error:
Failure: invalid input. Expected ā€˜Integerā€™ but found ā€˜xā€™

Standard Output Stream:
x y
Game information:
Failure: invalid input. Expected ā€˜Integerā€™ but found ā€˜xā€™

You printed it as a String instead of printing the values of your variables.

Hello,
on Java canā€™t parse the bombDir String variable. (p.s on JavaScript everything is ok).
Any help?

        while (true) {
        String bombDir = in.next(); // the direction of the bombs from batman's current location (U, UR, R, DR, D, DL, L or UL)
        System.out.println(bombDir);    // output: "DR"        
        boolean DR = bombDir == "DR"; 
        System.out.print(DR);            // output: false
    }
1 Like

You cannot use == to check for string equality in Java, because Strings are immutable.

You can use the inherited equals() method, or the equalsIgnoreCase() one.

3 Likes

thx a lot)

In the example given in this, Batman can move 2 in the x and 1 in the y directions. Did I miss this somewhere in the explanations, or descriptions?

Hi, Iā€™ve got the default section in scala for input here:

val Array(W, H) = (readLine split " ").map (.toInt)
val N = readLine.toInt // maximum number of turns before game over.
val Array(X0, Y0) = (readLine split " ").map (
.toInt)

But I get a slew of errors for that section, that look like this:

/tmp/Solution.scala:12: error: not found: value H
val Array(W, H) = readLine.split(" ").map(_.toInt)

Iā€™m pretty sure that thatā€™s a valid way to take in input, so Iā€™m not sure why itā€™s not working. Thanks!

For N - isnā€™t the constraint should be max ( log(w-x), log(h-y)) ?
correct if i am misunderstanding anything

ā€¦anyone can help me? only the last test canā€™t pass and whatā€™s more annoying, it just needs 2 more steps!!! :dizzy_face: :dizzy_face: :dizzy_face:
src below:

import java.util.*;

import java.io.*;

import java.math.*;

/**

 * Auto-generated code below aims at helping you parse

 * the standard input according to the problem statement.

 **/

class Data {

    private int step;

    public void setStep(int step){

        this.step=step;

    }

    public int getStep(){

        return this.step;

    }

}

class Player {

    // mind script: if X0+W/2< W, then X0+=W/2, or X0+W/4<W? X0+W/8<W?....

    // I have done my best...why can't you give me 2 more steps in 07!!!!!

    static int jumpMax(int init, int degree, int border, char pm){

        // ^ in java means XOR!!!

        int jump=border/(int)Math.pow(2,degree);

        if(pm=='+'){

            if(init + jump < border) return jump;

        }else if(pm=='-'){

            if(init - jump >= 0) return jump;

        }else{

        }

        // degree++ transfer the degree!!!

        return jumpMax(init,++degree,border,pm);

    }

    static Boolean jumpStep(Data d, String lastDir, Boolean care, String oppo, int init, int degree, int border, char pm){

        if(lastDir.contains(oppo) || care){

            int tmp=d.getStep()/2;

            d.setStep(tmp<1?1:tmp);

            return true;

        }else{

            d.setStep(jumpMax(init,degree,border,pm));

            return false;

        }

    }

    public static void main(String args[]) {

        Scanner in = new Scanner(System.in);

        int W = in.nextInt(); // width of the building.

        int H = in.nextInt(); // height of the building.

        int N = in.nextInt(); // maximum number of turns before game over.

        int X0 = in.nextInt();

        int Y0 = in.nextInt();

        Data lenX=new Data();

        Data lenY=new Data();

        lenX.setStep(0);

        lenY.setStep(0);

        Boolean[] takecare={false,false};

        String lastDir="any";

        // game loop

        while (true) {

            String bombDir = in.next();             
            
            String nextP=null;

            if (bombDir.equals("U")){

                takecare[1]=jumpStep(lenY,lastDir,takecare[1],"D",Y0,1,H,'-');

                Y0-=lenY.getStep();

            }else if (bombDir.equals("D")){

                takecare[1]=jumpStep(lenY,lastDir,takecare[1],"U",Y0,1,H,'+');

                Y0+=lenY.getStep();

            }else if (bombDir.equals("R")){

                takecare[0]=jumpStep(lenX,lastDir,takecare[0],"L",X0,1,W,'+');

                X0+=lenX.getStep();

            }else if (bombDir.equals("L")){

                takecare[0]=jumpStep(lenX,lastDir,takecare[0],"R",X0,1,W,'-');

                X0-=lenX.getStep();

            }else if (bombDir.equals("UR")){

                takecare[0]=jumpStep(lenX,lastDir,takecare[0],"L",X0,1,W,'+');

                takecare[1]=jumpStep(lenY,lastDir,takecare[1],"D",Y0,1,H,'-');

                X0+=lenX.getStep();

                Y0-=lenY.getStep();        

            }else if (bombDir.equals("UL")){   

                takecare[0]=jumpStep(lenX,lastDir,takecare[0],"R",X0,1,W,'-');  

                takecare[1]=jumpStep(lenY,lastDir,takecare[1],"D",Y0,1,H,'-');

                X0-=lenX.getStep();

                Y0-=lenY.getStep();

            }else if (bombDir.equals("DR")){

                takecare[0]=jumpStep(lenX,lastDir,takecare[0],"L",X0,1,W,'+');

                takecare[1]=jumpStep(lenY,lastDir,takecare[1],"U",Y0,1,H,'+');

                X0+=lenX.getStep();

                Y0+=lenY.getStep();

            }else if (bombDir.equals("DL")){

                takecare[0]=jumpStep(lenX,lastDir,takecare[0],"R",X0,1,W,'-');

                takecare[1]=jumpStep(lenY,lastDir,takecare[1],"U",Y0,1,H,'+');

                X0-=lenX.getStep();

                Y0+=lenY.getStep();

            }else {

            }

            nextP=X0+" "+Y0;

            lastDir=bombDir;

            // the location of the next window Batman should jump to.

            System.out.println(nextP);

        }

    }

}

yes I want some help please

same problem hereā€¦ Too bad, just no time to finish it for now, just 1 jump to the bottom and itā€™s ok!

how to solve this thing
:crying_cat_face: :crying_cat_face: