-------------------------------------------------------------------- Exo 1 interface [in] 2p utilisation de tableau [tab] 1p utilisation de listes comme élements du tableau [lis] 1p implementation [imp] 2p génie logiciel (indentation, etc) [gl] 1p prio.h #ifndef PRIO_H #define PRIO_H struct prio; typedef struct prio *prio; extern prio prio_create(int max_prio); extern void prio_destroy(prioq q); extern void prio_insert(prio p, void *element, int priority); extern void *prio_dequeue_max(prio p); extern int prio_empty(prio p); #endif prio.c #include "prio.h" #include "list.h" #include #include struct prio { list *table; int max_prio; int nb_elements; }; prio prio_create(int max_prio) { prio p = malloc(sizeof(struct prio)); p -> table = calloc(max_prio, sizeof(list)); p -> max_prio = max_prio; p -> nb_elements = 0; return p; } void prio_destroy(prioq q) { free(q -> table); free(q); } int prio_empty(prio p) { return p -> nb_elements == 0; } void prio_insert(prio p, void *element, int priority) { assert(priority >= 0 && priority <= p -> max_prio); p -> table[priority - 1] = cons(element, p -> table[priority - 1]); } void * prio_dequeue_max(prio p) { int i; assert(!prio_empty(p)); for(i = p -> max_prio - 1; !(p -> table[i]); i--) ; { list ltemp = p -> table[i]; void *temp = car(ltemp); p -> table[i] = cdr(p -> table[i]); free(ltemp); return temp; } } -------------------------------------------------------------------- Exo 2 utilisation de "block" [bl] 2p utilisation de return-from [rf] 2p syntaxe général [syn] 2p boucle [bouc] 1p (defmacro for (init until update &body body) (let ((out (gensym)) (cont (gensym))) `(block ,out ,init (do () ((not ,until)) (block ,cont (flet ((brk () (return-from ,out)) (cont () (return-from ,cont))) ,@body)) ,update)))) -------------------------------------------------------------------- Exo 3 Classes [cl] 2p Méthodes [me] 2p Implémentation [im] 1p Syntaxe [sy] 1p (defclass object () ;; whatever the labyrith needs, e.g., position, ... ()) (defclass tablet (object) ()) (defclass super-tablet (tablet) ()) (defclass mobile-object (object) ()) (defclass phantom (mobile-object) ()) (defclass pacman (mobile-object) ((force :initform 0 :accessor pacman-force) (invincible :initform nil :accessor pacman-invincible))) (defgeneric collision (obj1 obj2)) ;;; by default, do nothing (defmethod collision ((obj1 object) (obj2 object)) nil) (defmethod collision ((pac pacman) (tab tablet)) (incf (pacman-force)) (delete-object tab)) (defmethod collision :after ((pac pacman) (tab super-tablet)) (setf (pacman-invincible pac) t)) (defmethod collision ((pac pacman) (phan phantom)) (delete-object (if (pacman-invincible pac) phan pac))) (defmethod collision ((phan phantom) (pac pacman)) (collision pac phan))