Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ArrayList<String> data = new ArrayList<String>();
- void setup() {
- size(600, 800);
- //data.add("x,y,vy,wx0,wy0,wx1,wy1,clicked");
- }
- boolean clicked = false;
- int r, s=0, d=1, x, y=400, vy, wx[]= {0, 0}, wy[]= { 0, 0}, e=1800, l=600, hs=0, v=800;
- String prevline = "x,y,vy,wx0,wy0,wx1,wy1,clicked";
- void draw() {
- if (d==1) {
- text("HighScore: "+hs, 50, l);
- } else {
- background(255);
- imageMode(CENTER);
- rectMode(CENTER);
- 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)) {
- 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);
- 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);
- d = (abs(width/2-wx[i])<25 && abs(y-wy[i])>100) || y > height || y < 0 ? 1 : d;
- }
- String line = x+","+y+","+vy+","+wx[0]+","+wy[0]+","+wx[1]+","+wy[1]+",";
- if(data.size() > 0) prevline += clicked;
- clicked = false;
- data.add(prevline);
- println(prevline);
- prevline = line;
- int closestx = wx[0] < 300 ? wx[1] : wx[0];
- int closesty = wx[0] < 300 ? wy[1] : wy[0];
- //> closer <- ifelse(wx0 < 300,wx1,wx0)
- //> closery <- ifelse(wx0 < 300,wy1,wy0)
- // double decision = 8.078e-02 + 4.000e-03 * vy + -2.033e-04 * closer + 2.364e-07 * (closer*closery) + 3.435e-04 * (y-closery);
- // if(decision > 0.15) click();
- double decision = 1.893000e+00 + 1.660777e-01 *vy -1.177859e-02 * closestx + 4.979793e-06 *(closestx*closesty) + 1.560952e-02 * (y-closesty);
- println(decision);
- if(decision > 3) click();
- }
- }
- void click() {
- if (d==(vy=-17)/-17) y=(wx[1]=900) + 100 - ((wy[0]=(wy[1]=wx[0]=600)-200)+200 + (x = s = d = 0));
- clicked = true;
- }
- void mousePressed() { //Start learning Java for free: http://www.ktbyte.com/intro
- click();
- }
- void keyPressed() {
- String[] alllines = new String[data.size()];
- for(int i = 0 ; i < data.size(); i++) alllines[i] = data.get(i);
- saveStrings("data.csv",alllines);
- println("saved");
- }
- z <- read.csv("data.csv")
- lagpad <- function(x, k) { if(k>=0) { return(c(rep(NA, k), x)[1 : length(x)]) }else { x[(-k+1) : (length(x)-k)] } }
- attach(z)
- clicked2 <- clicked == "true"
- for(i in 1:3) clicked2 <- clicked2 | lagpad(clicked,-i) == "true"
- clicked2[is.na(clicked2)] <- FALSE
- closestx <- ifelse(wx0 < 300, wx1, wx0)
- closesty <- ifelse(wx0 < 300, wy1, wy0)
- glm.fit <- glm(clicked2 ~ vy + closestx + I(closestx*closesty) + I(y-closesty), family="binomial")
- glm.pred <- predict(glm.fit, type="response")
- table(glm.pred > 0.5,clicked)
- lm.fit <- lm(clicked2 ~ vy + closestx + I(closestx*closesty) + I(y-closesty))
- coef(lm.fit)
- #install.packages("Hmisc")
- library(Hmisc)
- latex(glm.fit)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement