{"cells":[{"metadata":{},"cell_type":"markdown","source":"# **The Game of Life**\n#### If you like it, welcome to upvote~\n**This is a simple version of EDA, and I will continue to refine it.**","execution_count":null},{"metadata":{},"cell_type":"markdown","source":"![](https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1599022311955&di=b8d13d89d8e0d2d2bf94a692af733504&imgtype=0&src=http%3A%2F%2F5b0988e595225.cdn.sohucs.com%2Fq_mini%2Cc_zoom%2Cw_640%2Fimages%2F20171011%2Fb375d651aefd4665b6960083f901b44a.jpeg)","execution_count":null},{"metadata":{},"cell_type":"markdown","source":"### There are four simple rules to determine the next state of the game board, given the current state:\n\n1. Overpopulation: if a living cell is surrounded by more than three living cells, it dies.\n1. Stasis: if a living cell is surrounded by two or three living cells, it survives.\n1. Underpopulation: if a living cell is surrounded by fewer than two living cells, it dies.\n1. Reproduction: if a dead cell is surrounded by exactly three cells, it becomes a live cell.","execution_count":null},{"metadata":{},"cell_type":"markdown","source":"\n<img src=\"https://qualityswdev.files.wordpress.com/2011/07/gameofliferules11.jpg\" width=\"450px\">","execution_count":null},{"metadata":{"trusted":true},"cell_type":"code","source":"import numpy as np\nimport pandas as pd\nimport matplotlib.pyplot as plt\nimport seaborn as sns\nimport matplotlib as mpl","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"train_df = pd.read_csv('../input/conways-reverse-game-of-life-2020/train.csv')\ntest_df = pd.read_csv(\"../input/conways-reverse-game-of-life-2020/test.csv\")\nprint(train_df.shape)\nprint(test_df.shape)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"train_df.head()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"colors = ['white','black'] \nbounds = [0,1] \ncmap = mpl.colors.ListedColormap(colors)\nnorm = mpl.colors.BoundaryNorm(bounds,cmap.N)\nfor i in range(3):\n    # convert to matrix\n    start = np.asarray(train_df.iloc[i][2:2+625])\n    start_mat = start.reshape(25,25)\n\n    # extract stop values\n    stop = np.asarray(train_df.iloc[i][2+625:])\n    stop_mat = stop.reshape(25,25)\n    \n    plt.rcParams['figure.figsize'] = (15.0, 7.0) #  Set the figsize\n    plt.figure()\n    plt.subplot(1,2,1)\n    plt.xlabel('start_map')\n    plt.imshow(start_mat,cmap = cmap)\n    plt.colorbar()\n\n    plt.subplot(1,2,2)\n    plt.xlabel('stop_map')\n    plt.imshow(stop_mat,cmap = cmap)\n    plt.colorbar()\n    plt.show()\n","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"### Let's try to add/minus them to find something between the begin and stop map.","execution_count":null},{"metadata":{"trusted":true},"cell_type":"code","source":"colors = ['black','white','yellow','blue'] \nbounds = [-1,0,1,2] \ncmap = mpl.colors.ListedColormap(colors)\nnorm = mpl.colors.BoundaryNorm(bounds,cmap.N)\nfor i in range(3):\n    # convert to matrix\n    start = np.asarray(train_df.iloc[i][2:2+625])\n    start_mat = start.reshape(25,25)\n    # extract stop values\n    stop = np.asarray(train_df.iloc[i][2+625:])\n    stop_mat = stop.reshape(25,25)\n    \n    plt.rcParams['figure.figsize'] = (15.0, 7.0) #  Set the figsize\n    plt.figure()\n    plt.subplot(1,2,1)\n    plt.xlabel('add')\n    plt.imshow(start_mat+stop_mat,cmap = cmap,norm = norm)\n    plt.colorbar()\n\n    plt.subplot(1,2,2)\n    plt.xlabel('minus')\n    plt.imshow(start_mat-stop_mat,cmap = cmap,norm = norm)\n    plt.colorbar()\n    plt.show()\n    ","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"","execution_count":null,"outputs":[]}],"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"pygments_lexer":"ipython3","nbconvert_exporter":"python","version":"3.6.4","file_extension":".py","codemirror_mode":{"name":"ipython","version":3},"name":"python","mimetype":"text/x-python"}},"nbformat":4,"nbformat_minor":4}