Advertisement
Guest User

Untitled

a guest
May 1st, 2017
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.82 KB | None | 0 0
  1. ArrayList<String> data = new ArrayList<String>();
  2. void setup() {
  3. size(600, 800);
  4. //data.add("x,y,vy,wx0,wy0,wx1,wy1,clicked");
  5. }
  6. boolean clicked = false;
  7. int r, s=0, d=1, x, y=400, vy, wx[]= {0, 0}, wy[]= { 0, 0}, e=1800, l=600, hs=0, v=800;
  8. String prevline = "x,y,vy,wx0,wy0,wx1,wy1,clicked";
  9. void draw() {
  10. if (d==1) {
  11. text("HighScore: "+hs, 50, l);
  12. } else {
  13. background(255);
  14. imageMode(CENTER);
  15. rectMode(CENTER);
  16. for (int i=0, z=y+=vy+=1, q= (x=x-6==-1800?0:x-6); i<2; i++, fill(0), textSize(40), ellipse(l/2, y,20,20)) {
  17. for (int j=-1; j<2; j+=2, text (""+s, l/2-15, 700)) rect(wx[i], wy[i]+j*(800/2+100),45,800);
  18. if ((wx[i]=wx[i]<0?(wy[i]=(int)random(200, v-200))/wy[i]*l:wx[i]-6)==l/2&&d==0) hs=max(++s, hs);
  19. d = (abs(width/2-wx[i])<25 && abs(y-wy[i])>100) || y > height || y < 0 ? 1 : d;
  20. }
  21. String line = x+","+y+","+vy+","+wx[0]+","+wy[0]+","+wx[1]+","+wy[1]+",";
  22.  
  23.  
  24. if(data.size() > 0) prevline += clicked;
  25. clicked = false;
  26. data.add(prevline);
  27. println(prevline);
  28. prevline = line;
  29.  
  30. int closestx = wx[0] < 300 ? wx[1] : wx[0];
  31. int closesty = wx[0] < 300 ? wy[1] : wy[0];
  32. //> closer <- ifelse(wx0 < 300,wx1,wx0)
  33. //> closery <- ifelse(wx0 < 300,wy1,wy0)
  34. // double decision = 8.078e-02 + 4.000e-03 * vy + -2.033e-04 * closer + 2.364e-07 * (closer*closery) + 3.435e-04 * (y-closery);
  35.  
  36. // if(decision > 0.15) click();
  37. double decision = 1.893000e+00 + 1.660777e-01 *vy -1.177859e-02 * closestx + 4.979793e-06 *(closestx*closesty) + 1.560952e-02 * (y-closesty);
  38. println(decision);
  39. if(decision > 3) click();
  40. }
  41. }
  42. void click() {
  43. if (d==(vy=-17)/-17) y=(wx[1]=900) + 100 - ((wy[0]=(wy[1]=wx[0]=600)-200)+200 + (x = s = d = 0));
  44. clicked = true;
  45.  
  46. }
  47. void mousePressed() { //Start learning Java for free: http://www.ktbyte.com/intro
  48. click();
  49. }
  50. void keyPressed() {
  51. String[] alllines = new String[data.size()];
  52. for(int i = 0 ; i < data.size(); i++) alllines[i] = data.get(i);
  53. saveStrings("data.csv",alllines);
  54. println("saved");
  55. }
  56.  
  57.  
  58.  
  59.  
  60.  
  61. z <- read.csv("data.csv")
  62. lagpad <- function(x, k) { if(k>=0) { return(c(rep(NA, k), x)[1 : length(x)]) }else { x[(-k+1) : (length(x)-k)] } }
  63. attach(z)
  64.  
  65. clicked2 <- clicked == "true"
  66. for(i in 1:3) clicked2 <- clicked2 | lagpad(clicked,-i) == "true"
  67. clicked2[is.na(clicked2)] <- FALSE
  68. closestx <- ifelse(wx0 < 300, wx1, wx0)
  69. closesty <- ifelse(wx0 < 300, wy1, wy0)
  70. glm.fit <- glm(clicked2 ~ vy + closestx + I(closestx*closesty) + I(y-closesty), family="binomial")
  71. glm.pred <- predict(glm.fit, type="response")
  72. table(glm.pred > 0.5,clicked)
  73.  
  74. lm.fit <- lm(clicked2 ~ vy + closestx + I(closestx*closesty) + I(y-closesty))
  75. coef(lm.fit)
  76. #install.packages("Hmisc")
  77. library(Hmisc)
  78. latex(glm.fit)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement