Dots game in Lisp

Discussion of Common Lisp

Dots game in Lisp

Postby vasko » Tue Mar 29, 2011 2:36 am

does anyone has link to a project of this game implemented in lisp?

or knows where I can find some useful info for this?

here is the game http://en.wikipedia.org/wiki/Dots_and_Boxes
vasko
 
Posts: 7
Joined: Mon Mar 21, 2011 4:45 pm

Re: Dots game in Lisp

Postby nuntius » Tue Mar 29, 2011 8:11 am

I haven't seen such. What is your need? Are you wanting to play with a friend, read some AI code, write your own AI, borrow a GUI, ...
User avatar
nuntius
 
Posts: 498
Joined: Sat Aug 09, 2008 10:44 am
Location: Burlington, MA

Re: Dots game in Lisp

Postby gugamilare » Tue Mar 29, 2011 11:06 am

I guess you will need to implement it yourself, if you want. You can take a look at Lisp Games Wiki and use Lispbuilder-SDL to create the game.

Good luck ;)
gugamilare
 
Posts: 406
Joined: Sat Mar 07, 2009 6:17 pm
Location: Brazil

Re: Dots game in Lisp

Postby vasko » Tue Mar 29, 2011 1:27 pm

I'll check these links now,thanks.

I want to find implementation example of this game in lisp and learn from it.

GUI should be simple ascii in console in alegro.
vasko
 
Posts: 7
Joined: Mon Mar 21, 2011 4:45 pm

Re: Dots game in Lisp

Postby nuntius » Tue Mar 29, 2011 5:19 pm

Here's a simple way of drawing the board in a console. I think a "normal" GUI might be easier for playing; but I played a cursor-driven version many years ago. The cursor on this board is denoted by an X.
Code: Select all
+-+-+-+-+
|A| | | |
+-+-+-+-+
| X |   |
+-+-+-+-+
| | | | |
+-+-+-+-+
User avatar
nuntius
 
Posts: 498
Joined: Sat Aug 09, 2008 10:44 am
Location: Burlington, MA

Re: Dots game in Lisp

Postby vasko » Wed Mar 30, 2011 4:34 am

yes,thats it

do you have function that draws NxN grid?
vasko
 
Posts: 7
Joined: Mon Mar 21, 2011 4:45 pm

Re: Dots game in Lisp

Postby nuntius » Wed Mar 30, 2011 10:12 am

Here's some code I wrote quickly to get you started.

Code: Select all
(defstruct box top left owner)

(defun make-random-boxes (rows cols)
  (let ((b (make-array (list rows cols))))
    (dotimes (i rows)
      (dotimes (j cols)
        (setf (aref b i j)
              (make-box
               :top (> (random 100) 50)
               :left (> (random 100) 50)
               :owner (and (> (random 100) 50) "A")))))
    b))

(defun print-boxes (boxes)
  "Print the boxes array to *standard-output*"

  (let ((rows (array-dimension boxes 0))
        (cols (array-dimension boxes 1)))
    (dotimes (r rows)
      ;; print tops then sides
      (dotimes (c cols)
        (with-slots (top) (aref boxes r c)
          (princ "+")
          (if (< (1+ c) cols)
            (princ (if top
                       "-"
                       " "))
            (princ #\Newline))))
      (when (< (1+ r) rows)
        (dotimes (c cols)
          (with-slots (left owner) (aref boxes r c)
            (princ (if left "|" " "))
            (if (< (1+ c) cols)
                (princ (or owner " "))
                (princ #\Newline))))))))


Here's sample output. I inserted two "."s because the forum wasn't showing a single leading space properly.
Code: Select all
(print-boxes (make-random-boxes 4 4))
+-+ + +
.A A A
+ + +-+
|A|A| 
+-+-+-+
.A|A|A
+ + +-+
Last edited by nuntius on Wed Mar 30, 2011 10:14 am, edited 1 time in total.
Reason: untabify the code
User avatar
nuntius
 
Posts: 498
Joined: Sat Aug 09, 2008 10:44 am
Location: Burlington, MA

Re: Dots game in Lisp

Postby vasko » Wed Mar 30, 2011 3:57 pm

thank you

I'll study it.

I need to add some seeking algorithm, some kind of AI to it.
vasko
 
Posts: 7
Joined: Mon Mar 21, 2011 4:45 pm

Re: Dots game in Lisp

Postby edgar-rft » Wed Mar 30, 2011 11:47 pm

Maybe this could be of interest:
Not Dots but Tic-Tac-Toe, using very similar AI algorithms:
edgar-rft
 
Posts: 155
Joined: Fri Aug 06, 2010 6:34 am
Location: Germany

Re: Dots game in Lisp

Postby vasko » Thu Mar 31, 2011 1:51 am

Edgar thank you very much!

I will study those examples.
vasko
 
Posts: 7
Joined: Mon Mar 21, 2011 4:45 pm


Return to Common Lisp

Who is online

Users browsing this forum: Yahoo [Bot] and 3 guests