#!/usr/bin/env bash # This is an example bot for the game Tui48. # All it does is print out some information, # and then it chooses a random action for # the game to do. # To use this bot, you can pass the path to # this file to Tui48: # $: tui48 --bot --bot-file /tmp/bot-file # If it wasn't already clear, this script was written with Linux in mind, # but you can easily port this to Windows. This script is just here to serve # as documentation and a demo. # Arguments: # 1: The path for the bot file. (This is where the final chosen action is written.) # 2: How many tiles are in a row, and how many rows are in the board? # 3: The current game score. # 4..: All the tile values. (0 == Empty Tile) file_path="$1" tile_count="$2" game_score="$3" shift 3 # Shift over all the command arguments. (The first tile is now argument 1.) echo "Bot File Path: '$file_path'" echo "Tile Count: $tile_count" echo "Game Score: $game_score" # This syntax is a bit confusing, but it is essentially just # printing out all the tile values and their position on the board. for i in $(seq 1 $(( ${tile_count} * ${tile_count} ))); do row=$(( $(( ${i} - 1 )) / ${tile_count} )) col=$(( $(( ${i} - 1 )) % ${tile_count} )) echo -n "(${col}, ${row}) = " if [[ "$1" == "0" ]]; then echo "EMPTY" else echo "$1" fi shift 1 done actions=( "up" "down" "left" "right" ) # Choose a random action. chosen_action=${actions[$(( ${RANDOM} % ${#actions[@]} ))]} echo "Chosen Action: '${chosen_action}'" # Save that action to the bot file. echo "${chosen_action}" > "${file_path}"