[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.lisp

Chess Bot in Common Lisp(automatic

Malice

12/27/2015 11:16:00 AM

I've never done that, so I want to write some simple chess bot that would, well... play chess. On some site. It would move automatically, et cetera, et cetera - I want to write it so that I could theoretically leave it for some time, come back, and it still would be playing.

I'm not doing that because I want to cheat - I want to learn.

Now I am asking how to do it(approach, rather than code) - mainly because I've never done it. I can read tutorials about e.g. minimax(and translate whatever language I find to Lisp), but the problem is plugging it into the web browser. I have no idea how to interact with my browser and get data from it. Has anyone ever done it? If so, how? Thanks in advance!
7 Answers

Tom Russ

12/27/2015 8:07:00 PM

0

On Sunday, December 27, 2015 at 3:16:39 AM UTC-8, Malice wrote:
>
> Now I am asking how to do it(approach, rather than code) - mainly because I've never done it.
> I can read tutorials about e.g. minimax(and translate whatever language I find to Lisp),
> but the problem is plugging it into the web browser. I have no idea how to interact with my
> browser and get data from it. Has anyone ever done it? If so, how? Thanks in advance!

OK, there are several parts here.

First, you need to write a program to play chess.
* This can be done off-line before you worry about writing the browser interaction.
* All by-itself this would be challenging.
* You probably will need this done before worrying about the web site interaction.

Second, you need to interact with the browser.
* For background, you should look into the GET and POST methods for HTTP requests.
* Then you need to select one of the web server packages that are available. It's been a while since
I have done anything like this, so you should get recommendations from others. Although a quick
look at Cliki.net suggests perhaps Drakma would work for you.
* You then need to GET the input page for the chess site.
-- Determine the state of the game. If it is just graphical, this could be a problem!
-- Determine if input is required (i.e., is it time for you to move? Have you instead lost or won?)
* Probably POST the information required by the interaction of the web site. This would be the form
contents that contains your input.
-- Set the proper input fields.
-- Send the properly encoded response to the web server.


Malice

12/27/2015 9:49:00 PM

0

On Sunday, 27 December 2015 21:06:51 UTC+1, Tom Russ wrote:
> OK, there are several parts here.
>
> First, you need to write a program to play chess.

I completely agree. This part I'm aware of, and I will probably do this first. I'm more concerned of second part.

>
> Second, you need to interact with the browser.
> * For background, you should look into the GET and POST methods for HTTP requests.
> * Then you need to select one of the web server packages that are available. It's been a while since
> I have done anything like this, so you should get recommendations from others. Although a quick
> look at Cliki.net suggests perhaps Drakma would work for you.

I've worked with drakma(slightly), it was fine.

> * You then need to GET the input page for the chess site.
> -- Determine the state of the game. If it is just graphical, this could be a problem!

I don't think so - even if it was graphical, graphics should be fixed, so some simple checks for colour in few pixels should do(or so I hope).

> -- Determine if input is required (i.e., is it time for you to move? Have you instead lost or won?)
> * Probably POST the information required by the interaction of the web site. This would be the form
> contents that contains your input.
> -- Set the proper input fields.
> -- Send the properly encoded response to the web server.

Now, this web thing is completely new to me- I've never done anything with it. Therefore, here goes the question that might be utterly stupid, but here it goes: if I understand what you're saying, you want me to start some server in background and use it to send and receive packages from the web client. That's fine by me, there should be some tutorial stuff around there. However, I am worried that this might not be what I'm looking for - I worry that it might be hard to either prove(from second server) that it's indeed me who's sending the request, or if I do this just okay - that notification will be sent to my server instead of browser(so I won't bet graphical update from web browser).

Of course I might be (and probably am) completely wrong, so feel free to correct me.

Dimitri Fontaine

12/27/2015 11:03:00 PM

0

Malice <gwmaniak@gmail.com> writes:
>> Second, you need to interact with the browser.
>> * For background, you should look into the GET and POST methods for HTTP requests.
>> * Then you need to select one of the web server packages that are available. It's been a while since
>> I have done anything like this, so you should get recommendations from others. Although a quick
>> look at Cliki.net suggests perhaps Drakma would work for you.
>
> I've worked with drakma(slightly), it was fine.

Well you will need an http server that serves your application: it
receives http requests and answers to them. I've been using hunchentoot
for that, I like it.

You could design a simple stateless API wherein the browser sends the
current game state and which color the server should find the best move
for, and you receive back an updated state.

That way, handling the state is the problem of the client, and it should
be easy enough to do in Javascript. Later when you want to save the
state in the server you will be able to add user accounts and ongoing
games and dashboards and whatnot, or just skip those parts.

> I don't think so - even if it was graphical, graphics should be fixed, so
> some simple checks for colour in few pixels should do(or so I hope).

You don't need any graphics for displaying a chess board as Unicode is
covering that for you:

https://en.wikipedia.org/wiki/Chess_symbols_...

> Now, this web thing is completely new to me- I've never done anything with
> it. Therefore, here goes the question that might be utterly stupid, but here
> it goes: if I understand what you're saying, you want me to start some
> server in background and use it to send and receive packages from the web
> client. That's fine by me, there should be some tutorial stuff around there.

Sounds a good start. Just try it on localhost and see what happens!

--
dim

taruss

12/28/2015 7:14:00 PM

0

On Sunday, December 27, 2015 at 1:49:34 PM UTC-8, Malice wrote:
> On Sunday, 27 December 2015 21:06:51 UTC+1, Tom Russ wrote:
> > OK, there are several parts here.
> >
> > First, you need to write a program to play chess.
>
> I completely agree. This part I'm aware of, and I will probably do this first. I'm more concerned of second part.
>
> >
> > Second, you need to interact with the browser.
> > * For background, you should look into the GET and POST methods for HTTP requests.
> > * Then you need to select one of the web server packages that are available. It's been a while since
> > I have done anything like this, so you should get recommendations from others. Although a quick
> > look at Cliki.net suggests perhaps Drakma would work for you.
>
> I've worked with drakma(slightly), it was fine.
>
> > * You then need to GET the input page for the chess site.
> > -- Determine the state of the game. If it is just graphical, this could be a problem!
>
> I don't think so - even if it was graphical, graphics should be fixed, so some simple checks for colour in few pixels should do(or so I hope).
>
> > -- Determine if input is required (i.e., is it time for you to move? Have you instead lost or won?)
> > * Probably POST the information required by the interaction of the web site. This would be the form
> > contents that contains your input.
> > -- Set the proper input fields.
> > -- Send the properly encoded response to the web server.
>
> Now, this web thing is completely new to me- I've never done anything with it. Therefore, here goes the question that might be utterly stupid, but here it goes: if I understand what you're saying, you want me to start some server in background and use it to send and receive packages from the web client. That's fine by me, there should be some tutorial stuff around there. However, I am worried that this might not be what I'm looking for - I worry that it might be hard to either prove(from second server) that it's indeed me who's sending the request, or if I do this just okay - that notification will be sent to my server instead of browser(so I won't bet graphical update from web browser).
>
> Of course I might be (and probably am) completely wrong, so feel free to correct me.

If I understand correctly, you want to build a web client that talks to a
third-party web server that actually runs the chess game.

So you would write a program that uses the client tools to interact with the
third-party web server. In effect, you will be building a programmatic web
"browser" that would play the part of a regular web browser when you interact
with the web site in the standard manner.

Whatever mechanism the web server uses to manage the interaction with the web
browser should also work when your program interacts with the browser. This
could be based on cookies, a hidden input field in the form, or some other
form of session id. As long as your client code properly acts like a regular
web client/browser, you should be able to interact with it.

You do have an advantage doing this from lisp, because you can try out parts of
the interaction and examine the results interactively as you build up the
system. As a start, you would want to GET the page from the web server and
see what it looks like. Then you could try to construct a proper response to
send and see if that works.

Where could this go wrong?
Well, if this is a JavaScript heavy interaction page, then it could be much
more difficult to work out the interactions, since a browser would be running
a program that manages the interaction rather than using the standard HTTP
GET/PUT/POST methods. You may still be able to figure out the API that the
page uses, but that would require more analysis of the page than if it is a
more standard HTTP/HTML page.

Gerd Flaig

1/7/2016 10:45:00 AM

0

taruss@google.com writes:

> [ remote controlling web chess ]
> Where could this go wrong?
> Well, if this is a JavaScript heavy interaction page, then it could be much
> more difficult to work out the interactions, since a browser would be running
> a program that manages the interaction rather than using the standard HTTP
> GET/PUT/POST methods. You may still be able to figure out the API that the
> page uses, but that would require more analysis of the page than if it is a
> more standard HTTP/HTML page.

Remote controlling an actual browser might also be an option, e.g. with
CL-Selenium.

Goodbyte, Gerd.
--
The last thing one knows in constructing a work is what to put first.
-- Blaise Pascal

Marco Antoniotti

1/7/2016 12:47:00 PM

0

On Thursday, January 7, 2016 at 11:44:47 AM UTC+1, Gerd Flaig wrote:
> taruss@google.com writes:
>
> > [ remote controlling web chess ]
> > Where could this go wrong?
> > Well, if this is a JavaScript heavy interaction page, then it could be much
> > more difficult to work out the interactions, since a browser would be running
> > a program that manages the interaction rather than using the standard HTTP
> > GET/PUT/POST methods. You may still be able to figure out the API that the
> > page uses, but that would require more analysis of the page than if it is a
> > more standard HTTP/HTML page.
>
> Remote controlling an actual browser might also be an option, e.g. with
> CL-Selenium.
>

It would is 'selenium' were still out there. Looks like you get a 404 now.

MA


Michael Maul

1/7/2016 2:31:00 PM

0

So if your interest in strictly the game playing part check out www.ggp.org and http://tiltyard.ggp.or.... This is a site dedicated to the field of game playing and offers the ability to play matches of various games against humans and computers one of which is chess. The only thing you would have to do is write a ggp client for Lisp. Coursera offers a course in General Game Playing that I though was quite interesting. I would have wrote one when I took the course but there was a clojure client....