This is a read-only archive of lispforum.com. The forum was locked to new users and posts and is preserved here as static HTML from a database snapshot taken on 2019-09-07.

Dots game in Lisp

10 posts · 9291 views

Re: Dots game in Lisp

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

Re: Dots game in Lisp

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

Re: Dots game in Lisp

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.

Re: Dots game in Lisp

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.
+-+-+-+-+
|A| | | |
+-+-+-+-+
| X |   |
+-+-+-+-+
| | | | |
+-+-+-+-+

Re: Dots game in Lisp

yes,thats it

do you have function that draws NxN grid?

Re: Dots game in Lisp

Here's some code I wrote quickly to get you started.
(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.
(print-boxes (make-random-boxes 4 4))
+-+ + +
.A A A 
+ + +-+
|A|A|  
+-+-+-+
.A|A|A 
+ + +-+

Last edited by nuntius on , edited 1 time in total. Reason: untabify the code

Re: Dots game in Lisp

thank you

I'll study it.

I need to add some seeking algorithm, some kind of AI to it.

Re: Dots game in Lisp

Maybe this could be of interest: Not Dots but Tic-Tac-Toe, using very similar AI algorithms:

Re: Dots game in Lisp

Edgar thank you very much!

I will study those examples.