From: Tiago Costa
Subject: othello(reversi) game problem!
Date: 
Message-ID: <ee40769d.0411280628.3c56a15c@posting.google.com>
I'm devoloping the othello game for a college work.

My problem is that whem one player makes a move the original
board(tab) is change. What i want to do is that the efectua-jogada
funtion return a board and not change the original board.

Any sugestion????

Thanks in advance!!!


(defun tab ()
  '(( 0 0 0 0 0 0 0 0 )
    ( 0 0 0 1 0 0 0 0 )
    ( 0 0 0 2 0 0 0 0 )
    ( 0 0 0 2 0 0 0 0 )
    ( 0 0 0 0 2 1 0 0 )
    ( 0 0 0 0 0 2 0 0 )
    ( 2 1 0 0 0 0 0 0 )
    ( 0 0 0 0 0 0 0 0 )
))


(defun efectua-jogada (tabuleiro jogador coluna linha)
  (let*
      (
       (liga (ligacoes tabuleiro jogador coluna linha))
       (tabu tabuleiro)
      )
       (loop 
         (cond
	   ((null liga) (return tabu))
	   (T (setf tabu (efectua-jogada-aux tabu jogador coluna linha (first
(first liga)) (first (rest (first liga))))))
         )
         (setf liga (rest liga))
       )
  )
)

From: Philip Haddad
Subject: Re: othello(reversi) game problem!
Date: 
Message-ID: <ba57c4f9.0411281227.6e36348d@posting.google.com>
···········@weblista.pt (Tiago Costa) wrote in message news:<····························@posting.google.com>...
> I'm devoloping the othello game for a college work.
> 
> My problem is that whem one player makes a move the original
> board(tab) is change. What i want to do is that the efectua-jogada
> funtion return a board and not change the original board.
> 
> Any sugestion????
> 
> Thanks in advance!!!
> 
> 
> (defun tab ()
>   '(( 0 0 0 0 0 0 0 0 )
>     ( 0 0 0 1 0 0 0 0 )
>     ( 0 0 0 2 0 0 0 0 )
>     ( 0 0 0 2 0 0 0 0 )
>     ( 0 0 0 0 2 1 0 0 )
>     ( 0 0 0 0 0 2 0 0 )
>     ( 2 1 0 0 0 0 0 0 )
>     ( 0 0 0 0 0 0 0 0 )
> ))
> 
> 
> (defun efectua-jogada (tabuleiro jogador coluna linha)
>   (let*
>       (
>        (liga (ligacoes tabuleiro jogador coluna linha))
>        (tabu tabuleiro)
>       )
>        (loop 
>          (cond
> 	   ((null liga) (return tabu))
> 	   (T (setf tabu (efectua-jogada-aux tabu jogador coluna linha (first
> (first liga)) (first (rest (first liga))))))
>          )
>          (setf liga (rest liga))
>        )
>   )
> )

OK, first of all, that code looks like crap! Second of all, if you
want the efectua-jogada function to return the board unscathed, you
simply have to return it. The last object of any function is what the
function returns. So after
(setf liga (rest liga))
do
(tab)...))))
that should make the function return the board.
One last thing: write the code in english please.

-- 
Certum quod factum.
Philip Haddad
From: Pascal Bourguignon
Subject: Re: othello(reversi) game problem!
Date: 
Message-ID: <87act1g59u.fsf@thalassa.informatimago.com>
···········@weblista.pt (Tiago Costa) writes:

> I'm devoloping the othello game for a college work.
> 
> My problem is that whem one player makes a move the original
> board(tab) is change. What i want to do is that the efectua-jogada
> funtion return a board and not change the original board.
> 
> Any sugestion????
> 
> Thanks in advance!!!
> 
> 
> (defun tab ()
>   '(( 0 0 0 0 0 0 0 0 )
>     ( 0 0 0 1 0 0 0 0 )
>     ( 0 0 0 2 0 0 0 0 )
>     ( 0 0 0 2 0 0 0 0 )
>     ( 0 0 0 0 2 1 0 0 )
>     ( 0 0 0 0 0 2 0 0 )
>     ( 2 1 0 0 0 0 0 0 )
>     ( 0 0 0 0 0 0 0 0 )
> ))

Since it'a a table, use an array:

(defun tab ()
   #2A(( 0 0 0 0 0 0 0 0 )
       ( 0 0 0 1 0 0 0 0 )
       ( 0 0 0 2 0 0 0 0 )
       ( 0 0 0 2 0 0 0 0 )
       ( 0 0 0 0 2 1 0 0 )
       ( 0 0 0 0 0 2 0 0 )
       ( 2 1 0 0 0 0 0 0 )
       ( 0 0 0 0 0 0 0 0 )))
 
 
> (defun efectua-jogada (tabuleiro jogador coluna linha)
>   (let*
>       (
>        (liga (ligacoes tabuleiro jogador coluna linha))
>        (tabu tabuleiro)
>       )
>        (loop 
>          (cond
> 	   ((null liga) (return tabu))
> 	   (T (setf tabu (efectua-jogada-aux tabu jogador coluna linha (first
> (first liga)) (first (rest (first liga))))))
>          )
>          (setf liga (rest liga))
>        )
>   )
> )

Make a copy of the array and modify the copy:


(defun copy-array (array &key copy-fill-pointer copy-adjustable
                   copy-displacement)
  (when copy-displacement
    (multiple-value-bind (disto disoff) (array-displacement array)
      (when disto
        (return-from copy-array
          (make-array (array-dimensions array)
                            :element-type (array-element-type array)
                            :displaced-to disto
                            :displaced-index-offset disoff
                            :adjustable (when copy-adjustable 
                                         (adjustable-array-p array))
                            :fill-pointer (when copy-fill-pointer
                                            (fill-pointer array)))))))
  (let ((copy (make-array (array-dimensions array)
                           :element-type (array-element-type array)
                           :adjustable (when copy-adjustable 
                                        (adjustable-array-p array))
                           :fill-pointer (when copy-fill-pointer
                                           (fill-pointer array))
                           :initial-element (row-major-aref array 0))))
    (dotimes (i (array-total-size copy))
      (setf (row-major-aref copy i) (row-major-aref array i)))
    copy));;copy-array


(defun cell-empty-p (tablueiro coluna linha)
  (zerop (aref tablueiro coluna linha)))


(defun efectua-jogada (tabuleiro jogador coluna linha)
  (when (cell-empty-p tabuleiro coluna linha)
    (let ((tabu (copy-array tabuleiro)))
      (setf (aref tab cluna linha) jogador)
      tabu)))



-- 
__Pascal Bourguignon__                     http://www.informatimago.com/
The world will now reboot; don't bother saving your artefacts.
From: David Sletten
Subject: Re: othello(reversi) game problem!
Date: 
Message-ID: <jFsqd.123363$Kl3.21413@twister.socal.rr.com>
Pascal Bourguignon wrote:

> 
> (defun cell-empty-p (tablueiro coluna linha)
                        ^^^^^^^^^
>   (zerop (aref tablueiro coluna linha)))
> 
> 
> (defun efectua-jogada (tabuleiro jogador coluna linha)
                          ^^^^^^^^^
>   (when (cell-empty-p tabuleiro coluna linha)
>     (let ((tabu (copy-array tabuleiro)))
>       (setf (aref tab cluna linha) jogador)
>       tabu)))
> 
> 
> 

Wow, that's tough working in two non-native languages (English, 
Portuguese), Pascal! :) (I'm assuming you're French.) At least you were 
consistent within each definition, so your code should run. :)

David Sletten