code-bullet / pool_ai Goto Github PK
View Code? Open in Web Editor NEWI created an AI to play pool, and here it is
I created an AI to play pool, and here it is
the error says
No library found for shiffman.box2d
No library found for org.jbox2d.common
No library found for org.jbox2d.dynamics.joints
No library found for org.jbox2d.collision.shapes
No library found for org.jbox2d.collision.shapes
No library found for org.jbox2d.common
No library found for org.jbox2d.dynamics
No library found for org.jbox2d.dynamics.contacts
Libraries must be installed in a folder named 'libraries' inside the sketchbook folder (see the Preferences window)
The two top holes are not registering...a.k.a the balls roll on them without disapearing
something like the following works nice for me:
//apply friction to the balls
for (int i =0; i<balls.length; i++) {
balls[i].update();
balls[i].isInHole();
}
whiteBall.update();
Line 51 in f2eb2e0
Thanks for the source code, I been wanting to get in to AI for a while now, something like this is exactly what I needed to start. Thank you much. You said it's made with Processing, I wonder if Java can run it with some modification? I am learning Java and can read the code without no problem at all.
So I get that the number of the colored balls are equal to the number of player balls, and I don't like the way that looks so I'm just trying to change the popSize to be equal to 1 so that it works better but for some reason and i'm not sure if I'm just dumb but when I set it to 1 the screen will not show any balls at all. the lowest has to be 2 and I'm not 100% why, if I'm just missing something please tell me I'm dumb
Population pop;//the population of pool players
Box2DProcessing[] box2d;//each player needs an individual world so this array stores them
int popSize = 1;//the amount of players tested at once
table[] tables;//each player also needs a table
int speed = 60;//frameRate
boolean showSingle = false;//whether only one player needs to be shown because they are all the same
boolean saveFrames = true;//true if it the first gen after increasing the number of shots so it saves the full game not just the last shot
//------------------------------------------------------------------------------------------------------------------------------------------------------------------
void setup() {
size(400, 800);
frameRate(speed);//set the initial frame rate
//initialise worlds and tables
box2d = new Box2DProcessing[popSize];
tables = new table[popSize];
for (int i = 0; i< box2d.length; i++) {//create each of the worlds and add a table to them
box2d[i] = new Box2DProcessing(this);
box2d[i].createWorld();
box2d[i].setGravity(0, 0);//no gravity
tables[i] = new table(box2d[i]);
}
pop = new Population(popSize);//create the population
}
IF Required How to Go TO the Game While Running The Code
//import box2d physics engine
import shiffman.box2d.;
import org.jbox2d.common.;
import org.jbox2d.dynamics.joints.;
import org.jbox2d.collision.shapes.;
import org.jbox2d.collision.shapes.Shape;
import org.jbox2d.common.;
import org.jbox2d.dynamics.;
import org.jbox2d.dynamics.contacts.*;
Population pop;//the population of pool players
Box2DProcessing[] box2d;//each player needs an individual world so this array stores them
int popSize = 200;//the amount of players tested at once
table[] tables;//each player also needs a table
int speed = 60;//frameRate
boolean showSingle = false;//whether only one player needs to be shown because they are all the same
boolean saveFrames = true;//true if it the first gen after increasing the number of shots so it saves the full game not just the last shot
//------------------------------------------------------------------------------------------------------------------------------------------------------------------
void setup() {
size(400, 800);//this it the part not working
frameRate(speed);//set the initial frame rate
//initialise worlds and tables
box2d = new Box2DProcessing[popSize];
tables = new table[popSize];
for (int i = 0; i< box2d.length; i++) {//create each of the worlds and add a table to them
box2d[i] = new Box2DProcessing(this);
box2d[i].createWorld();
box2d[i].setGravity(0, 0);//no gravity
tables[i] = new table(box2d[i]);
}
pop = new Population(popSize);//create the population
}
//------------------------------------------------------------------------------------------------------------------------------------------------------------------
void draw() {
background(0, 200, 0);//green background
tables[0].show();//show the cushions and holes
if (pop.foundWinner) {//if one of the population has sunk all the balls then replay it and record it
if ((!pop.players[pop.bestPlayerNo].gameOver && !pop.players[pop.bestPlayerNo].won )|| !pop.players[pop.bestPlayerNo].ballsStopped()) {//while not done replaying
box2d[pop.bestPlayerNo].step(); //step the world through time
pop.players[pop.bestPlayerNo].update();//update the player
pop.players[pop.bestPlayerNo].show(); // show the player
saveFrame("output/15Ball/finalgame/frame_#######.png");//save the frame as an image
}
} else {//if solution not found
if (!pop.done()) {//while players still playing
stepBoxes();//step through time in the physics engine
pop.update();//update players
pop.show();//show balls
} else {
//genetic algorithm
pop.calculateFitness();
pop.setBestPlayer();//sets best player and checks if it won
if (!pop.foundWinner) {//if the best player didnt win
if (pop.generation % 5 == 0) {//every 5 generation
pop.resetPopulation();//set all the population as the best player then add one shot to the end of them
showSingle = true;//only show one of the players
saveFrames = true;//save all of the next game to show which shot was added to the end
} else {
pop.naturalSelection();//create new generation based on fitness
showSingle = true;//only show one of the players
}
}
}
}
}
//------------------------------------------------------------------------------------------------------------------------------------------------------------------
void keyPressed() {
switch(key) {
case '+'://increase game speed
speed+= 10;
frameRate(speed);
break;
case '-'://decrease game speed (to a min of 10)
if (speed>10) {
speed-= 10;
frameRate(speed);
}
break;
}
}
//------------------------------------------------------------------------------------------------------------------------------------------------------------------
void stepBoxes() { //step through time in all the boxes
for (int i = 0; i< box2d.length; i++) {
box2d[i].step();
}
}
//------------------------------------------------------------------------------------------------------------------------------------------------------------------
void resetWorlds() {//reset all the worlds to remove all the bodies from them
for (int i = 0; i< popSize; i++) {
box2d[i] = new Box2DProcessing(this);
box2d[i].createWorld();
box2d[i].setGravity(0, 0);
tables[i] = new table(box2d[i]);
}
}
After that is says size() cannot be used
Giving me error "The package “shiffman” does not exist. You might be missing a library."
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.