Recognizing colors/patterns in webpage - java

I want to try to create a learning chess application as a school project. My first plan was to simply pit this AI against itself, but to really show if it has been succesful it needs to be able to show how well it progresses. In order to do this, i want it to play rated games on sites such as chess.com. However, they do not (yet) have a public API, i believe.
Therefore, i wanted to make a program in java that recognizes colors and images. It keeps an internal 2-dimensional array of all the positions, and recognizes the pieces on the board. I think i have found a way to do this in a window using something like the Java Robot Class.
What i would like it to do, however, is to open this webpage in an internal window and keep doing this in the background. Is there a way to recognize colors within the own window, without needing to be in the foreground?
Edit: I'm planning on using this browser component i just found. I noticed that it is possible to create a full-page snapshot of the page and save it as a BufferedImage(?). Would this make it easier to do this?
Edit 2: I just read that 'Outside assistance from other people, computers/chess engines, or endgame tablebases is entirely prohibited'. I suppose letting a computer do all the playing does certainly include in that. So i might try using another site, so answers that are specific for chess.com won't cut it!

I don't know it it helps but may be you can have a look at the Sikuli project.
http://sikuli.org/
Sikuli is a program (and an API) to handle the interactions with the User Interface. For instance, you can write a script to click on an image or a button in certain conditions.
Especially interesting for you, there is a Java integration: http://sikuli.org/docx/faq/030-java-dev.html
Here is an extract of the website to give you an idea of the code you can write.
EDIT: in this code it is important to notice that you are defining new Patterns with the images. Sikuli will be able to find matching patterns.
import org.sikuli.script.*;
public class TestSikuli {
public static void main(String[] args) {
Screen s = new Screen();
try{
s.click("imgs/spotlight.png", 0);
s.wait("imgs/spotlight-input.png");
s.type(null, "hello world\n", 0);
}
catch(FindFailed e){
e.printStackTrace();
}
}
}

You should consider playing on a chess server where an API is avaible and chess engines are allowed. There is The Internet Chess Club (ICC) where you must pay to have a human account and then you can get a free computer account for your engine. There is also the Free Internet Chess Server (FICS) where you and your engine can get free accounts.
The ICC is usually prefered because the level of players is higher there with lots of international masters and chess masters playing there.
The best way to Interface with theses sites is to implement the xboard protocol. This will allow your engines to play through the Winboard or XBoard interface (among others) and theses interface can be used to connect on FICS or ICC and automatically play there.
I hope this help, even if it does not directly answer the question.

I'm not sure what your input is but you have two options:
You can work an a PNG image. Load the image into a BufferedImage (docs) object and examine it there. You can use a screen shot tool to create those.
It seems chess.com uses HTML with JavaScript. You can download the HTML using HttpComponents and examine it to see where the pieces are. This has the additional benefit that you don't have to guess which piece goes where since the HTML contains the source information.

Related

Is it possible to create a custom screen GUI in Bukkit?

I'm wondering if it's possible to add some custom screen GUI's to my Bukkit server. So I can display a lot of text on someone's screen. Or do I need to find another option to do this?
Thanks!
The only practical way is to use an Inventory using blocks with name and lore for users to click on as can be seen here
As Cole Nelson mentioned, a custom inventory with lore displayed might work. A good guide for that can be found on the bukkit forums, and although it's a bit outdated it should still provide useful information.
Another possibility would be to utilize title screens; obviously those can't hold a ton of information, but the player is pretty much guaranteed to notice them immediatly.
I recommend using Title Api, as it's a bit tedious to directly work with packets.
Once you added the jar to your project and set the dependency, simply use:
TitleAPI.sendTitle(player,fadeIn,stay,fadeOut,"Title","Subtitle");
to send a title with all corresponding attributes.
Example result:

Java program to read information from a website

I am writing a program in Java that will help track a "Fantasy College Basketball" league for my friends. I am struggling with finding the best implementation to automatically update the statistics for each player drafted.
As some background, every day individuals in the fantasy league earn points based on statistics that college basketball players they drafted earned that week. Right now, I do this mannually:
1: Go to a player's ESPN profile
ESPN tracks individual player stats with a URL that is based on a random and unique player ID number. Frank Kaminsky's ID is 56759, so his ESPN profile is: http://espn.go.com/mens-college-basketball/player/_/id/56769/. We can assume that the user will input a player's ESPN ID when the player is drafted and we will have that information when updating stats.
2: Parse HTML page to get relevant stats
Looking at the URL above - the important information is in the "2014 - 2015 Game Log" section. I would want to obtain the most recent game's PTS, REB, AST, BLK, STL, PF, and TO to use elsewhere in my program.
What is the best approach to this?
My first reaction was to use a .openStream() on a URL, but this would require a lot of careful string parsing. The HTML really isn't pretty line by line...
I have heard of jsoup, but haven't used it ever before. If people here think that is the best way to proceed, I'd be happy to learn how to use it.
Use Jsoup, it is easy to learn and made for the job.
The JSoup website has a nice tutorial on it.
Have a look here: http://jsoup.org/cookbook/input/load-document-from-url
Then parse your document with the methods explained here: http://jsoup.org/cookbook/extracting-data/selector-syntax
I would recommend http://www.seleniumhq.org/
This is an external library but it is really easy to use and learn. Normally it is used to test websites but it is really multi-purposed.
Driver driver = new ChromeDriver();
driver.get("http://yoursitehere.iamnotarealsite");
That would be the code to open a chrome browser and to navigate to your site. To find elements you can do things like:
WebElement stats=driver.findElement(By.cssSelector("div#statsOrSomething"));
And you can use standard get text functions on WebElements:
stats.getText();//Gets players stats
Also did I mention that it has many language bindings including Java? Also: I don't work for selenium or its parent company so this is not a shameless plug.

Implementing auto completion in Java

I was working on creating a weather application in Java using Weather Underground and I found that it does have data for some cities.
Initially, I was planning on using GeopIP to get the user's location automatically but since the support for cities is limited I decided to let the user choose the city every time the program starts.
I want the user to be able to choose a city from one that is supported by Weather Underground. The user will enter the name and as he/she enters the name, the possible locations will be displayed in a way similar to the one shown in the picture.
My question is:
How do I implement this search feature ?
My initial guess was to create a Vector containing all the names of the cities and then use brute force to find the match and display in a JPopup or a JWindow containing a JList but I guess there has to be a better method
Rephrase:
What I do not understand is WHAT INFO do I keep in the data structure I must use ? Should I manually create a list of cities that Weather Underground supports or is there another way to do it ?
Take a look at the Trie data structure (also known as digital tree or prefix tree). Autocompletion is one of the most common examples of it's usefulness.
The following article has a nice an very approachable explanation:
Roll your own autocomplete solution using Tries.
if you google autosuggestcombobox you will get some interesting results:
This one is written in JavaFX - I have used and extended it myself already. It is quite useful. What you get "for free" with JavaFX: a context menu with right-mouse click which is auto-generated containing some of the usual "stuff", like cut, copy & paste and even undo! So, I can recommend that solution. To get into JavaFX isn't so hard - and I think it is much easier to learn than Swing - and looks so much cooler! However this implementation has some drawbacks - especially when the layout is not left-aligned, because it is simply a text field on top of a combobox.
OK - but if you want to stick to Swing - you could probably use this one. I haven't used that myself, but the code looks quite straightforward and pretty clean - cleaner than the implementation for JavaFX I must admit (but that had some nice features). So - maybe you try - and extend it? It is built simply on JComboBox.

OpenGL JOGL Camera that can be moved by keyboard

I really need a simple camera that i could use with my application. I would like to be able to control the movement of the camera with the keyboard. I only really require that it moves forwards and backwards and rotates with respect to the y-axis.
thanks in advance for any help as i don't know where to start with this one. Many tutorials around on google, but not for jogl :/
among the files included with downloading the official jogl things you can download (demos, tutorials, etc) is included the 'gleem' package, which I've used and quite like.
gleem stands for: GL-E-E-M: GL Extremely Easy-to-use Manipulators
here's the original page for gleem: http://alumni.media.mit.edu/~kbrussel/gleem/#DEMOS (with some pretty images, and context for)
link to source downloads within the offical-ish jogl page: http://java.net/projects/jogl
anyway, however you get it, amongst the file check out these specific options:
gleem.TestExaminerViewer.java
gleem.TestHandleBox.java
gleem.TestMultiWin.java
gleem.TestTranslate1.java
gleem.TestTranslate2.java
gleem.Translate1Manip.java
gleem.Translate2Manip.java
and, I'd expect you'll find what you're looking for. gl
PS - I'm boldy guessing/assuming that you want to control some sort of 'camera' that can be seen, vs. per-say just updating the model_matrix stack (if the later, of course just tie your key bindings to the different values you pass in as you call to update the matrix stack, ala using 'gluLookAt' ... etc)

Odontogram code

I need to add an odontogram to my webpage.
It looks like this:
I would like to know if there is already some kind of open source odontogram.
I am using spring-mvc so it has to be in java
If it's web based I'd think you'd just want to return an SVG from a servlet.
If it must be interactive, I'd do this as an Applet or JWS application, with each tooth represented by an instance extending JComponent and containing five Polygons. The latter would make filling and hit testing relatively easy. A simple data model containing surface (proximal, distal, lingual, labial, occlusal) and color-code would also be useful. See also ImageTooth.
Addendum: You may want to plan on consulting a subject matter expert regarding the clinical correlation of the numbers, colors and locations.

Categories

Resources