Created
June 11, 2016 20:56
-
-
Save svanellewee/efa902938374fd9fd3ead4df719f93a2 to your computer and use it in GitHub Desktop.
Tictactoe from https://www.youtube.com/watch?v=gk39mp8Vy4M with my slant
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; tictactoe.el -- play tic tac toe in emacs | |
(defun start-tictactoe () | |
"Start playing the game" | |
(interactive) | |
(switch-to-buffer "ticktacktoe") | |
(tictactoe-mode) | |
(tictactoe-init) | |
(tictactoe-print-board) | |
(tictactoe-swap-players)) | |
(defun tictactoe-swap-players () | |
(setq *tictactoe-current-player* (if (char-equal *tictactoe-current-player* ?\X) ?\O ?\X))) | |
(define-derived-mode tictactoe-mode special-mode "tic-tac-toeeee") | |
(defun tictactoe-init () | |
"Start a neew game with tititt" | |
(setq *tictactoe-board (make-vector (* *tictactoe-size* *tictactoe-size*) ?\.))) | |
(defvar *tictactoe-board* nil | |
"The board itself.") | |
(defconst *tictactoe-size* 3 | |
"the size!!!") | |
(setq *tictactoe-board* (make-vector (* *tictactoe-size* *tictactoe-size*) ?\.)) | |
(defun tictactoe-print-board () | |
(let ((inhibit-read-only t)) | |
(erase-buffer) | |
(dotimes (row *tictactoe-size*) | |
(dotimes (column *tictactoe-size*) | |
(insert (tictactoe-get-square row column)) | |
) | |
(insert "\n")))) | |
(defun tictactoe-get-square (row column) | |
"Get the row blabla" | |
(elt *tictactoe-board* (+ (* row *tictactoe-size*) column))) | |
(defun tictactoe-set-square (row column value) | |
"set the row blabla" | |
(aset *tictactoe-board* (+ (* row *tictactoe-size*) column) value)) | |
(defun tictactoe-mark () | |
"mark square" | |
(interactive) | |
(let ((row (1- (line-number-at-pos))) | |
(column (current-column))) | |
(tictactoe-set-square row column *tictactoe-current-player*) | |
(tictactoe-print-board) | |
(tictactoe-swap-players))) | |
(defvar *tictactoe-current-player* nil | |
"current character!") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment