{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Chain Reaction\n", "Chain reaction is a _deterministic combinatorial game_ of perfect information \n", "for 2 - 8 players developed by Matt Buddy. \n", "The rules of the two-player(Red and Green) game are: \n", "- The game takes place on a n × m board.\n", "- Each cell has a critical mass. The critical mass of a cell is equal to the number of orthogonally adjacent cells.(4 for inner cells, 3 for edge cells and 2 for corner cells)\n", "- All cells are initially empty. Each player can place orbs of their corresponding colours in an empty cell or a cell already contains one or more orbs of the same colour.\n", "- When a cell reaches its critical mass, it immediately explodes and an orb is added to each of its orthogonally adjacent neighbours. This may result in neighbouring cells to reach their critical mass. The chain reaction of explosions continue untill every cell is stable.\n", "- When a cell explodes near cell of different colour, those cells are converted to the exploding cell colour and normal explosion rules follow.\n", "- The winner is the one who eliminates all orbs of the other colour.\n", "\n", "\n", "A sample 3 player game is shown below" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [], "source": [ "%%bash\n", "#clears all the pics\n", "rm -f pics/*" ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "
" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "%config IPCompleter.greedy=True\n", "%matplotlib inline\n", "from core import Board\n", "from random import choice\n", "def test():\n", " rows, cols = 9, 6\n", " no_of_games = 1\n", " no_of_players = 3\n", " no_of_moves_avg = 0\n", " board = Board(rows=rows, cols=cols, no_of_players=no_of_players)\n", " cnt = 0\n", " while not board.game_complete():\n", " for i in range(no_of_players):\n", " pos = choice(board.valid_moves())\n", " board.play(pos, mid_states=False)\n", " #print(\"Move:\" + str(pos))\n", " a = str(cnt)\n", " a = \"0\"*(4-len(a)) + a\n", " figname = \"pics/fig\" + a\n", " board.drawGraphical(figname)\n", " cnt += 1\n", " if board.game_complete():\n", " break\n", " assert(board.verify_game_over())\n", "test()" ] }, { "cell_type": "code", "execution_count": 9, "metadata": {}, "outputs": [], "source": [ "%%bash\n", "convert -delay 20 -loop 0 pics/*.png pics/myimage.gif" ] }, { "cell_type": "code", "execution_count": 11, "metadata": {}, "outputs": [ { "data": { "text/html": [ "" ], "text/plain": [ "" ] }, "execution_count": 11, "metadata": {}, "output_type": "execute_result" } ], "source": [ "from IPython.display import HTML\n", "HTML('')" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.5.2" } }, "nbformat": 4, "nbformat_minor": 2 }