Today again it was pleasant surprise by Google on Basketball day, they posted a doodle to let us play basket ball. And again I thought to use the same code which I used yesterday [see here]
So my best score achieved with manual results was "33", and with my code my best was "39".
Here goes my code:
#include <X11/Xlib.h>
#include <X11/keysym.h>
#include <X11/extensions/XTest.h>
Display *display;
unsigned int keycode;
int main(int argc, char *argv[]){
display = XOpenDisplay(NULL);
int i=0;
int slp=198000;
keycode = XKeysymToKeycode(display, 0x020);
while(1){
i++;
if(i%13==0)
{
slp=slp+134000;
}
XTestFakeKeyEvent(display, keycode, True, 0);
usleep(slp);
XTestFakeKeyEvent(display, keycode, False, 0);
XFlush(display);
}
}
You can do the same with java code:
import java.awt.*;
import java.awt.event.KeyEvent;
public class Basketball {
public static void main(String[] s) throws AWTException
{
Robot robot = new Robot();
robot.delay(3000);
int i=1,r=1;
int j=230;
int k=0;
while(i==1)
{
robot.keyPress(KeyEvent.VK_SPACE);
robot.delay(j);
robot.keyRelease(KeyEvent.VK_SPACE);
robot.delay(15);
k++;
if(k%5==0)
{ r++;
j=r*95;
}
}
}
}
You can slice and dice some constants to get better results.
Just compile and run the code and quickly go to the browser where the game window should be ready for execution, and just win win win.