AIBob.py 1.2 KB

1234567891011121314151617181920212223242526272829303132
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-"
  3. """
  4. PyAISnake - 2018/2020 - by psy (epsylon@riseup.net)
  5. You should have received a copy of the GNU General Public License along
  6. with PyAISnake; if not, write to the Free Software Foundation, Inc., 51
  7. Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  8. """
  9. from curses import KEY_RIGHT, KEY_LEFT, KEY_UP, KEY_DOWN
  10. import random
  11. # random movements strategy (but) evading suicidal behavior (you can easily identify some humans trying this way of life)
  12. class AIBob(object):
  13. def extractName(self):
  14. name = "BoB"
  15. return name
  16. def makeMove(self, win, prev_move, food, snake):
  17. name = self.extractName()
  18. if prev_move == KEY_UP:
  19. allowed_moves = [KEY_UP, KEY_LEFT, KEY_RIGHT]
  20. elif prev_move == KEY_LEFT:
  21. allowed_moves = [KEY_UP, KEY_LEFT, KEY_DOWN]
  22. elif prev_move == KEY_RIGHT:
  23. allowed_moves = [KEY_UP, KEY_RIGHT, KEY_DOWN]
  24. elif prev_move == KEY_DOWN:
  25. allowed_moves = [KEY_LEFT, KEY_RIGHT, KEY_DOWN]
  26. else:
  27. allowed_moves = [KEY_UP, KEY_LEFT, KEY_RIGHT, KEY_DOWN]
  28. move = random.choice(allowed_moves)
  29. return move