Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

LISP: A dynamic car

Name: Anonymous 2012-01-30 20:27

I have a complex list of lists and want something to check the second element of every list of the list in the loop, any supported features like this?

Name: luke 2012-02-02 22:01

>>40

5 x 8

five could be taken to represent man (3) and his anima (2) (/shadow) [or a woman(2) and her animus (3)?]

eight as infinity...

the neverending battle of good vs evil? = 40?? =D

Name: Anonymous 2012-02-02 22:24

>>41
cretin

Name: Lua 2012-02-03 8:51

Why don't you use Lua as your go to scripting language?

Name: Anonymous 2012-02-13 20:44

the dynamic car keeps on truckin next stop, dub central

also can anyone here explain to me what defsetf does and the proper way to do it. I'm reading an Othello program and i see

(defun bref (board square) (aref board square))
  (defsetf bref (board square) (val)
  `(setf (aref ,board ,square) ,val))


and no matter how long i look at this or examine the function that's calling it i can't make out it's intended purpose

also the link to the othello program if you want to see the calls or whatever
http://norvig.com/paip/othello.lisp

Name: Anonymous 2012-02-13 21:39

>>44
It tells setf how to modify the value of a call to bref, for example (setf (bref x y) z). It can't just call bref and modify that, because it will return something by value instead of by reference.

Name: Anonymous 2012-02-13 21:46

>>45
i still don't understand, sorry

Name: Anonymous 2012-02-13 22:19

>>46
When you write (setf (car x) y), this is what it doesn't do:

(let ((z (car x)))
  (setf z y))


z just contains the value of (car x), not a pointer to it. So (setf z y) wouldn't actually modify the cons cell, and the code wouldn't work.

Instead, when setf sees the call to car, it passes the cons cell to rplaca, which modifies the car.

defsetf tells setf which function you want it to call when you have (setf (bref x y) z). In the code you posted, that will expand to (setf (aref x y) z), which well then expand to whatever code setf was told to use to set an aref form.

Name: Anonymous 2012-02-13 22:24

>>47
alright i have a general idea, now time to look up aref

thank you

Name: Anonymous 2012-02-13 22:27

>>48
okay aref is simple enough just an array access element

again thanks wouldn't have figured it out on my own for awhile

Name: Anonymous 2012-02-13 22:39

>>48-49
If you're still not completely sure about how it works, chapter 12 of On Lisp (http://www.paulgraham.com/onlisptext.html) talks about setf, and section 12.5 is about defsetf.

Name: Anonymous 2012-02-19 14:39

can someone aid me here?
illegal syntax by setq x (read)


(defun get-move ()
(setq counter (+ counter 1))
 (let* ((x 9) )
(when (eql (mod counter 2) 0)
 (setq x (check-for-win))
 (if null x
  (setq x (check-for-loss))
    (if null x
      (setq x (random-get))
    )
 )
 (setf (aref board-values x) 2)
 (setf (aref board-symbols x) 'O)
)

(when (eql (mod counter 2) 1)
(print "Enter a number between 1 and 9: ")
(loop until (and (>= x 0) (<= 8 x) (valid-move x)
;;;;ERROR HERE;;;;;;;;;;;
   (setq x (read))
   (setq x (- x 1))
  )
 (setf (aref board-values x) 1)
 (setf (aref board-symbols x) 'X)
))

Name: Anonymous 2012-02-19 14:42

playing with a full deck get

Name: Anonymous 2012-02-19 14:56

>>51
Your parentheses are imbalanced, and based on your indentation, I don't think your ifs are doing what you want them to. First of all, null x needs to be inside parentheses. Also, in the first if expression, the inner if is part of the else block - it will be executed if x is non-null.

Here are some other suggestions. They're mostly style things, so they're not causing any problems, but they'll make your code look nicer.

(setq counter (+ counter 1)) -> (incf counter)
let* is unnecessary in this case - use let.
(if (null x) ...) -> (unless x ...) if there's no else
(equal (mod counter 2) 0) -> (evenp counter) - same for 1, oddp

As for the problem in the loop, close the parenthesis around and, and then you need the loop keyword do.

Name: Anonymous 2012-02-19 15:00

>>53
I feel retarded for getting do, time to sudoku

otherwise, thank you for the tips, didn't even know about evenp and oddp

Name: Anonymous 2012-02-19 18:54

>>55
look at this faggots dubs

Name: Anonymous 2012-02-19 20:55

I feel like I'm abusing when also

http://pastebin.com/3hGHGyGT
 This unholy mass is not functioning correctly

ideally i wanted to think of it as if 1 2 3  = 1 then return T for win/placement, but it doesn't seem to want to work

the players number is 1
the computers number is 2


(defun checkwin (board &optional player)
 (print "in check win")
(when (null player)
  (setq player 2)
 )
 (block nil
(when (eql (aref board 0) player)
 (when (and (eql (aref board 0) (aref board 1)) (eql (aref board 1) (aref board 2))) (return T))
 (when (and (eql (aref board 0) (aref board 4)) (eql (aref board 1) (aref board 8))) (return T))
 (when (and (eql (aref board 0) (aref board 3)) (eql (aref board 1) (aref board 6))) (return T))
)
(when (eql (aref board 1) player)
 (when (and (eql (aref board 1) (aref board 5)) (eql (aref board 7) (aref board 5)))  (return T))
)
(when (eql (aref board 2) player)
 (when (and (eql (aref board 2) (aref board 4)) (eql (aref board 1) (aref board 3))) (return T))
 (when (and (eql (aref board 2) (aref board 5)) (eql (aref board 1) (aref board 8))) (return T))
)
(when (eql (aref board 3) player)
 (when (and (eql (aref board 3) (aref board 4)) (eql (aref board 1) (aref board 5))) (return T))
)
(when (eql (aref board 6) player)
 (when (and (eql (aref board 6) (aref board 7)) (eql (aref board 1) (aref board 8))) (return T))
))
)


also please critizise coding style

Name: Anonymous 2012-02-19 20:57

>>56
I'm off today, meant to use code tags

I feel like I'm abusing when also

http://pastebin.com/3hGHGyGT
 This unholy mass is not functioning correctly

ideally i wanted to think of it as if 1 2 3  = 1 then return T for win/placement, but it doesn't seem to want to work

the players number is 1
the computers number is 2


(defun checkwin (board &optional player)
 (print "in check win")
(when (null player)
  (setq player 2)
 )
 (block nil
(when (eql (aref board 0) player)
 (when (and (eql (aref board 0) (aref board 1)) (eql (aref board 1) (aref board 2))) (return T))
 (when (and (eql (aref board 0) (aref board 4)) (eql (aref board 1) (aref board 8))) (return T))
 (when (and (eql (aref board 0) (aref board 3)) (eql (aref board 1) (aref board 6))) (return T))
)
(when (eql (aref board 1) player)
 (when (and (eql (aref board 1) (aref board 5)) (eql (aref board 7) (aref board 5)))  (return T))
)
(when (eql (aref board 2) player)
 (when (and (eql (aref board 2) (aref board 4)) (eql (aref board 1) (aref board 3))) (return T))
 (when (and (eql (aref board 2) (aref board 5)) (eql (aref board 1) (aref board 8))) (return T))
)
(when (eql (aref board 3) player)
 (when (and (eql (aref board 3) (aref board 4)) (eql (aref board 1) (aref board 5))) (return T))
)
(when (eql (aref board 6) player)
 (when (and (eql (aref board 6) (aref board 7)) (eql (aref board 1) (aref board 8))) (return T))
))
)

also please critizise coding style

Name: Anonymous 2012-02-19 22:11

>>57
Sorry, I don't feel like debugging it, but I'll make some more style suggestions.

For defining new variables (lines 5-9) you should use defparameter.
This is up to you, but I always use setf for consistency, even when setq will work. They compile to the same code.
For lines 25-29 and 35-59, I would use cond. For example, the first would be (cond ((evenp counter) ...) (t ...)).
Lines 35-44, without the prints, are equivalent to (setq y (or (check-for-win) (check-for-loss) (random-get))). That's assuming that those functions only return either a number or nil.
Lines 52-53 - (setq x (1- (read)))
Line 60 - (when (< -1 x 9) ...) - same for 76
Lines 76-78 - (and (<= 0 x 8) (= (aref board-values x) 0))

I'm done for now, if you post a new version I'll look at it tomorrow.

Name: Anonymous 2012-02-20 1:05

lisp is shit

Name: Anonymous 2012-02-20 8:36

You could do this in D

Name: Anonymous 2012-02-20 10:38

>>58
thanks for that, made your changes and found my problem

Name: Anonymous 2012-03-19 18:05

vroom vroom and we're back because fucking stumped

(defun gen-list (turn boards)
"minimax"
 (let ((bestscore -2) (tempscore -2)) ;keeps track of score
   (print "ALPHA")
   (listp (free-return boards))   ;;debugging statement
   (when (or (eql (free-return boards) nil) (eql turn 9)) ;;error occurs here the second time, expected type list
     (return-from gen-list bestscore)
   )
                                  (print "A")
   (if (evenp turn)
    (setf bestscore -2) ;;forces the computer to pick a move
    (setf bestscore 2))  
                                         (print "B")
(loop for x in (free-return boards) do ;gets all free areas in the form of a list
                                       (print "C")
  (when (evenp turn)                  ;;if computers turn
                                   (print "D")
   (setf (car (nth x boards)) 2)   ;;sets element at position x
                                   (print "E")
(when (checkwin boards)           ;;if there is a victory
                                  (print "F")
 (setf tempscore 1))              ;;set temp to 1
                                  (print "G")
(when (not (eql tempscore 1))
                                   (print "H")
 (if (checkwin boards 1)         ;;if the opponent has the win
  (setf tempscore 0)             ;;set score to 0
  (setf tempscore -1)            ;;else -1
                             
)))                                 (print "I")

(when (oddp turn)      ;;if players turn just perform a move
(print boards ) (terpri) (terpri) ;debug
                                       (print "J")
 (setf (car (nth x boards)) 1)
                                     (print "k")
)
                                     (print "L")
(setf tempscore (gen-list (+ 1 turn)  (free-return boards))); send
                                      (print "M")
 (setf (car (nth x boards)) 0) ;;returns board to passed value so it can try another value
                                      (print "N")
;;if it's the computers turn and a better move has been found update it
(when (and (evenp turn) (> tempscore bestscore))
 (setf bestmove x)
 (setf bestscore tempscore)
))
(return-from gen-list bestmove)
))

(defun free-return (boards)
"returns every available position to move"
(loop for x from 0 to 8 when (eql (car (nth x boards)) 0) collect x))

Name: Anonymous 2012-03-19 18:40

>>60
You could do it in Brainfuck too.

Name: Anonymous 2012-05-01 21:28

somebody give me an effective simple heuristic for evaluating checker position

for now I have a value board where I some up all the places then add 1 if pawn and 2 if king then subtract it from the opponents which is similar

however this is concentrated shit as I've found.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List