Dots game in Lisp

Discussion of Common Lisp
Post Reply
vasko
Posts: 7
Joined: Mon Mar 21, 2011 4:45 pm

Dots game in Lisp

Post by 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

nuntius
Posts: 538
Joined: Sat Aug 09, 2008 10:44 am
Location: Newton, MA

Re: Dots game in Lisp

Post by 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, ...

gugamilare
Posts: 406
Joined: Sat Mar 07, 2009 6:17 pm
Location: Brazil
Contact:

Re: Dots game in Lisp

Post by 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 ;)

vasko
Posts: 7
Joined: Mon Mar 21, 2011 4:45 pm

Re: Dots game in Lisp

Post by 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.

nuntius
Posts: 538
Joined: Sat Aug 09, 2008 10:44 am
Location: Newton, MA

Re: Dots game in Lisp

Post by 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 |   |
+-+-+-+-+
| | | | |
+-+-+-+-+

vasko
Posts: 7
Joined: Mon Mar 21, 2011 4:45 pm

Re: Dots game in Lisp

Post by vasko » Wed Mar 30, 2011 4:34 am

yes,thats it

do you have function that draws NxN grid?

nuntius
Posts: 538
Joined: Sat Aug 09, 2008 10:44 am
Location: Newton, MA

Re: Dots game in Lisp

Post by 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

vasko
Posts: 7
Joined: Mon Mar 21, 2011 4:45 pm

Re: Dots game in Lisp

Post by 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.

edgar-rft
Posts: 226
Joined: Fri Aug 06, 2010 6:34 am
Location: Germany

Re: Dots game in Lisp

Post by 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:

vasko
Posts: 7
Joined: Mon Mar 21, 2011 4:45 pm

Re: Dots game in Lisp

Post by vasko » Thu Mar 31, 2011 1:51 am

Edgar thank you very much!

I will study those examples.

Post Reply