Created
August 17, 2016 09:34
-
-
Save VitoVan/cfe443022a6d865f26668bfd06f88eea to your computer and use it in GitHub Desktop.
Chrome dino-ai (
This file contains 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
(defpackage #:dino-ai | |
(:use #:common-lisp #:cl-autogui) | |
(:export #:dino-jump)) | |
(in-package #:dino-ai) | |
(defvar *space-key* 65) | |
;; game over text position (position of 'G' and 'R') | |
(defvar *game-over-poses* '((385 175) (575 173))) | |
;; the position of the head of dino | |
(defvar *dino-head-x* 250) | |
(defvar *dino-head-y* 220) | |
;; Position to test background color | |
(defvar *bg-test-x* 190) | |
(defvar *bg-test-y* 150) | |
(defvar *day-bgcolor* '(247 247 247 255)) | |
(defvar *block-color-white* '(172 172 172 255)) | |
(defvar *block-color-black* '(83 83 83 255)) | |
(defun block-color () | |
"Check it's day or night, return the correct color of dino (and same as blocks)" | |
(if (x-snapsearch *day-bgcolor* :x *bg-test-x* :y *bg-test-y* :width 1 :height 1) | |
*block-color-black* | |
*block-color-white*)) | |
(defun game-over? () | |
(every #'consp | |
(mapcar | |
#'(lambda (pos) | |
(x-snapsearch (block-color) | |
:x (car pos) | |
:y (cadr pos) | |
:width 1 :height 1)) | |
*game-over-poses*))) | |
(defun find-block (&key default) | |
(or (x-snapsearch (block-color) | |
:x *dino-head-x* | |
:y *dino-head-y* | |
:width 500 | |
:height 35) | |
default)) | |
(defun dino-jump () | |
(x-press *space-key*)) | |
(defparameter *last-block-speed* 0) | |
(defparameter *last-block-x* 0) | |
(defun dino-play () | |
;; move to dino and click | |
(x-click :x *bg-test-x* :y *bg-test-y*) | |
(when (game-over?) (dino-jump)) | |
(sleep 1) | |
(loop | |
(when (game-over?) (return)) | |
(let ((block-distance (- (car (find-block :default '(9999))) *dino-head-x*))) | |
(sleep 0.2) | |
(format t "DIS: ~S~%" block-distance) | |
(when (< block-distance 200) | |
(dino-jump))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment