{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Lab 5 (Option 2 Trailer) - Settlers of Catan\n", "\n", "#### Authors:\n", "\n", "v1.0 (2016 Spring) Kabir Chandrasekher, Tony Duan, David Marn, Ashvin Nair, Kangwook Lee, Kannan Ramchandran\n", "\n", "This trailer introduces you to a modified version of the board game \"Settlers of Catan\". If you choose to do the Catan project, you will come up with a probabilistic model of Catan and optimize a strategy to dominate opponents! _Just run through this trailer to get a preview of the project -- there is no code to write._\n", "\n", "## Introduction\n", "The goal of the game is to get $10$ victory points as fast as possible. To get these points, the player must choose a wise trade-off between spending resources to potentially obtain points and upgrading their modes of production. You, the chieftain of the island, must decide where and when to build additional settlements on the island to boost your resource production. Alternatively, you can invest into development cards, which will bring you a victory point, or upgrade a settlement into a city which doubles production and gives you another victory point. A village must border on a resource field in order to harvest its resources. We will have three different terrains: forests, which produce wood, hills which produce brick, and fields of grain (grain). Every turn, we roll two dice and record the sum $X$. The settlements that are next to the tile that is labelled with $X$ get one resource from that field, and we keep collecting resources and building up to 10 victory points.\n", "\n", "## Game layout\n", "\n", "Our modified Catan board is drawn below.\n", "\n", "Tiles are color coded with the resource they produce: wood, brick, grain.\n", "\n", "You build settlements and cities on vertices of the board. The small green square is a settlement, labeled \"1\" because it gives you one resource of the surrounding tiles when the corresponding number is rolled. The small blue square is a city and gives you 2 resources from surrounding tiles." ] }, { "cell_type": "code", "execution_count": 6, "metadata": { "collapsed": true }, "outputs": [], "source": [ "import numpy as np\n", "from catan import Catan, CatanException, get_random_dice_arrangement, Player, simulate_game, simulate_game_and_save\n", "import matplotlib.pyplot as plt\n", "from itertools import repeat\n", "%matplotlib inline\n", "width, height = 3, 3\n", "dice = get_random_dice_arrangement(width, height)\n", "resources = np.random.randint(0, 3, (height, width))\n", "board = Catan(dice, resources, [5], [10])" ] }, { "cell_type": "code", "execution_count": 8, "metadata": { "collapsed": false }, "outputs": [ { "data": { "image/png": "iVBORw0KGgoAAAANSUhEUgAAAO0AAAD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hcAAAAASUVORK5CYII=\n", "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "board.draw()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "\n", "## Rules\n", "When implementing the game, remember to follow these rules:\n", "
\n", "
• Every turn you roll 2 dice, call the sum X
• \n", "
• Find the tiles labeled with the number X and collect one of that resource for every settlement and two of that resource for every city on a vertex of that tile
• \n", "
• You can never have more than 4 of any resource: if you get extra, you just keep 4
• \n", "
• You can build by paying resources according to the costs below, and building anything gives you 1 victory point
• \n", "
\n", "\n", "## Costs\n", "You can build villages, which boost your production (but bring no victory points), or buy development cards which can bring you an additional victory point.\n", "\n", "The costs are given below, and stored in the array costs for convenience." ] }, { "cell_type": "code", "execution_count": 17, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
woodbrickgrain
settlement 2 3 1
card 1 1 2
city 4 2 2
" ], "text/plain": [ "" ] }, "execution_count": 17, "metadata": {}, "output_type": "execute_result" } ], "source": [ "import numpy as np\n", "import pandas as pd\n", "\n", "costs = np.array([[2, 3, 1],\n", " [1, 1, 2],\n", " [4, 2, 2]])\n", "\n", "resources = ['wood', 'brick', 'grain']\n", "buildings = ['settlement', 'card', 'city']\n", "df = pd.DataFrame(costs, index=buildings, columns=resources)\n", "html = df.to_html()\n", "from IPython.core.display import HTML\n", "HTML(html)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## $\\mathcal{Q}$1. Learning the Game" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The Catan board is implemented for you, with utilities to draw and get a table of resources gained. In particular you will find these two functions useful:\n", "\n", "board = Catan(dice, resources, settlements, cities)\n", "\n", "The constructor initializes our Catan board. Dice and resources must be the same shape: HxW where H is the height of the board and W is the width. dice[i,j] is the dice number that tile corresponds to (each element between 2-12 inclusive) and resources[i,j] is the resource that tile provides. Settlements is a list of vertices with settlements on them, and likewise for cities.\n", "\n", "board.get_resources()\n", "\n", "This returns a 11x3 numpy array of resources gained for each possible dice sum. That is, r[i, :] = resources gained from throwing a (i+2)." ] }, { "cell_type": "code", "execution_count": 4, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "[[ 0. 0. 0.]\n", " [ 0. 1. 0.]\n", " [ 1. 0. 0.]\n", " [ 2. 0. 0.]\n", " [ 0. 0. 0.]\n", " [ 0. 4. 0.]\n", " [ 0. 0. 0.]\n", " [ 0. 0. 2.]\n", " [ 0. 0. 0.]\n", " [ 0. 2. 0.]\n", " [ 0. 0. 0.]]\n" ] }, { "data": { "image/png": "iVBORw0KGgoAAAANSUhEUgAAAO0AAADtCAYAAABTTfKPAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAADB9JREFUeJzt3X9snPV9wPH33Tk25zghP+xgQhYTnJSSSRTo2hWYRhat\nXWnaoGqYrktVDTZ16x9rAWk/pE5TNGnamLSJroL9UWma2KAMilYKWaetUpcKCilrC9pqJLxlZE5o\nUjtxYmwS/7h79sedQ+z4fI5j+3k+5/dLOtn3w9KHL/fO89zznO5ySZIgKY582gNIujRGKwVjtFIw\nRisFY7RSMEYrBWO0UjBN83lQLpfzZK60jJIkydW6b17RAjy+c+fiTNOg9vX2wv60pwhgv8+levb1\n9s55v7vHUjBGKwVjtFIwRisFY7RSMEYrBWO0UjBGKwVjtFIwRisFY7RSMEYrBWO0UjBGKwVjtFIw\nRisFY7RSMEYrBWO0UjBGKwVjtFIwRisFY7RSMPP+3OMsOT4+zoHBQfrOnuXo2BjvbW3lj6699qLH\nPTswwLeHhhgplbiuWOSznZ10XXHF8g+cpteB7wAngTXAzwO3pjpRphw8fZqvvvXWRbffd/XV7F6/\nPoWJ6gsZ7bGxMV4bGWF7ayulJGG2j2J/dnCQbwwO8utX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4+PjlJKE\n/W++edF9v9vXx6516/itzZuXf7AMibhGDRPti9Wf21KdIluub23lS11d0257bWSE50+e5Pe3bmXT\nqlUpTZYdEdcoZLQfBT4M7AQKVIL9K+DXMNoLrWlq4oam6f+LfzpROTF2fWsrLfnQr44WRcQ1Chnt\nB4G/o7Ir3AR0A3+Op3y0MoSM9k+qF126O9at445169IeI9OyvkbZ2/ZLmpPRSsEYrRSM0UrBGK0U\njNFKwRitFIzRSsEYrRSM0UrBGK0UjNFKwRitFIzRSsEYrRSM0UrBGK0UjNFKwRitFIzRSsEYrRSM\n0UrBGK0UjNFKwRitFIzRSsEYrRSM0UrBGK0UjNFKwRitFIzRSsEYrRSM0UrBGK0UTC5JkvoPyuXq\nP0jSokmSJFfrvnlFKyk73D2WgjFaKRijlYIxWikYo5WCMVopGKOVgvl/gU2n5xHV6J4AAAAASUVO\nRK5CYII=\n", "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "board.draw()\n", "print board.get_resources()\n", "# wood is brown, brick is red, grain is green\n", "# below is the resource outcome of a dice roll" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Game Simulation\n", "\n", "Run the code below to see a game in action! This will use our (bad) sample policy." ] }, { "cell_type": "code", "execution_count": 7, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "546.76\n" ] } ], "source": [ "# sample action function\n", "def action(self, resources, costs):\n", " # inputs:\n", " # resources - an array of resources\n", " # costs - an array of costs, 0 - settlement, 1 - card, 2 - city\n", " # basic strategy: Once we get 4 of one resource and less than 2 of any other, we make a trade. \n", " # Then we try to buy development cards\n", " if self.board.settlements == []:\n", " x = np.random.randint(0, self.board.width + 1)\n", " y = np.random.randint(0, self.board.height + 1)\n", " self.board.build(x, y, \"settlement\")\n", " if self.if_can_buy(\"card\"):\n", " self.buy(\"card\")\n", " elif self.resources[np.argmax(self.resources)] >= 4 and self.resources[np.argmin(self.resources)] < 2:\n", " rmax, rmin = np.argmax(self.resources), np.argmin(self.resources)\n", " self.resources[rmax] -= 4\n", " self.resources[rmin] += 1\n", " return\n", "\n", "num_trials = 100\n", "print simulate_game(action, board, num_trials)" ] }, { "cell_type": "code", "execution_count": 8, "metadata": { "collapsed": false }, "outputs": [], "source": [ "settlements, cities, hands, live_points, dice_rolls = simulate_game_and_save(action, board)\n", "\n", "def draw(t):\n", " t = int(t)\n", " live_board = Catan(board.dice, board.resources, [], [])\n", " live_board.settlements = settlements[t]\n", " live_board.cities = cities[t]\n", " print \"turn:\", t\n", " print \"points:\", live_points[t]\n", " print \"dice roll:\", dice_rolls[t]\n", " print \"resources:\", hands[t]\n", " live_board.draw()" ] }, { "cell_type": "code", "execution_count": 9, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "turn: 1757\n", "points: 10\n", "dice roll: 3\n", "resources: [ 0. 1. 0.]\n" ] }, { "data": { "image/png": "iVBORw0KGgoAAAANSUhEUgAAAO8AAAD1CAYAAAC4PaJEAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAADZxJREFUeJzt3WtsW4d5h/HnkBRFUpREyRRlyRdZjhs7ipd23ZY2XbcE\nbtI2a1a0Q9Jkc5BsXYF1wYoCazNgCLAZWz5sQNemw4Ah6NauBrx0TdKgWIN0S9eL0yXuZS2MLWoc\nx4ldybqYkkxSEinxdvaBlCPLutC1rXNe6f8DDJCHB8KrYz48FxKi47ouImJPwOsBROQXo3hFjFK8\nIkYpXhGjFK+IUYpXxCjFK2JU6HJWdhxHbwqLrCPXdZ2VHruseAGODAxc2TQb3MHBQW2jBmg7re3g\n4OCqj+uwWcQoxStilOIVMUrxihileEWMUrwiRileEaMUr4hRilfEKMUrYpTiFTFK8YoYpXhFjFK8\nIkYpXhGjFK+IUYpXxCjFK2KU4hUxSvGKGKV4RYxSvCJGKV4Roy777zb7zfcyGb4wMnLJ8o/29HCg\no8ODifzpx7kcT6XTjBWLJEIh3tfZyZ1btng9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qf53NAQf97XR0AXrK6dXZEIANfHYsSDQR4fGeG3k0lS4bDHk3kv\nHgySCocvhAu17RRyHM7Ozyte4CvnznFzWxv3LTpi64tEePjUKf5neppfa2vzcLrl+fuM/Be0EHK6\nVPJ4En/obW5muct3LuC//Yk30sUifUvObXuamwk7Dud8+jzakPG+WigA0KWLMQD8cmsrQ3NzTJfL\nF5a9ks9TcV366i90m10yHOaNubmLlp2dn6four59Hpk/bP7bM2fYH4+zLRwm4Di8ms/z3NQU72xr\n0yFz3YFEgv+YmuLvhob4YDJJoVrlK+Pj7G9p4fpYzOvxfOGOjg6+PDZGx9hY7Zy3UuGZdJqupibe\nFo97Pd6yzMd7XTTK0UyGiVKJANAdDnNvKsXteqvogmgwyCN9fRweG+MfhocJOQ6/2tbG/boif8Ed\nnZ0EHYfnp6b4diZDNBBgXyzGvakUYZ++32s+3rtTKe5Opbwew/e6w2Ee3rnT6zF87UBHxyWf2PMz\nf76kiMiaFK+IUYpXxCjFK2KU4hUxSvGKGKV4RYxSvCJGKV4RoxSviFGKV8QoxStilOIVMUrxihil\neEWMUrwiRileEaMUr4hRilfEKMUrYpTiFTFK8YoYpXhFjFK8IkYpXhGjFK+IUYpXxCjFK2JUQ180\n5jjOhe9mPjg4uOJ6RwYGrsJIItKIhuI9xKGrso6IXD06bBYxaq097x7g4Y8f/zhdN3Zx5ugZDh84\nvB5zicga1op3ALgz/bM0gVAA3DXWFpF1s9Zh878DO5++72nSg+n1mEdEGrRWvNrXivhUQ1ebG7Xa\n20ibibZDY7SdrsxVjdd1Xedq/jwRWZnjug0fGT8FdAIHrt04ItIovc8rYpTiFTFK8YoYtdYFqyjw\ngfrtbUArcHf9/rNA4RrNJSJrWOuC1S7g9frthRWd+u1+4OfXbDIRWdXlXG0WER/ROa+IUYpXxCjF\nK2KU4hUxSvGKGKV4RYxSvCJGKV4Ro/4fsqYlNASTJGAAAAAASUVORK5CYII=\n", "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "from IPython.html.widgets import *\n", "interact(draw, t=(0, len(live_points) - 1, 1))" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "In the Catan project you will work on building a Markov chain for the game to analyze it formally, and calculate the expected time to build buildings. Then, you will come up with a policy to play the game and work on some creative extension of your choice.\n", "\n", "If you're choosing Catan, open up the Catan lab notebook, where we've written some skeleton code to direct you Enjoy!" ] } ], "metadata": { "kernelspec": { "display_name": "Python 2", "language": "python", "name": "python2" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 2.0 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython2", "version": "2.7.11" } }, "nbformat": 4, "nbformat_minor": 0 }