Guest User

Untitled

a guest
Mar 20th, 2014
84
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package pkg2048ai;
  2.  
  3. import java.awt.AWTException;
  4. import java.awt.Robot;
  5. import java.awt.event.InputEvent;
  6. import java.awt.event.KeyEvent;
  7.  
  8. public class Main {
  9.  
  10. public static void main(String[] args) {
  11. while (true) {
  12. int x = 0;
  13. while (x < 300) {
  14. try {
  15. x += 1;
  16. int num = (int) (Math.random() * 3) + 1;
  17. Robot robot = new Robot();
  18.  
  19. if (num == 1) {
  20. robot.keyPress(KeyEvent.VK_DOWN);
  21. robot.keyRelease(KeyEvent.VK_DOWN);
  22. } else if (num > 1) {
  23. robot.keyPress(KeyEvent.VK_RIGHT);
  24. robot.keyRelease(KeyEvent.VK_RIGHT);
  25. }
  26.  
  27. try {
  28. Thread.sleep(5L);
  29. } catch (Exception e) {
  30. }
  31.  
  32. } catch (AWTException e) {
  33. e.printStackTrace();
  34. }
  35. }
  36. try {
  37. Robot robot = new Robot();
  38. int num2 = (int) (Math.random() * 5) + 1;
  39. if (num2 < 5) {
  40. robot.keyPress(KeyEvent.VK_UP);
  41. robot.keyRelease(KeyEvent.VK_UP);
  42. } else {
  43. robot.keyPress(KeyEvent.VK_LEFT);
  44. robot.keyPress(KeyEvent.VK_LEFT);
  45. }
  46. } catch (AWTException e) {
  47. e.printStackTrace();
  48.  
  49. }
  50.  
  51. }
  52. }
  53. }
RAW Paste Data