Skip to content

Instantly share code, notes, and snippets.

@omikun
Last active November 10, 2017 01:50
Show Gist options
  • Save omikun/9dcdbdbc205adeacdafbc616fba88446 to your computer and use it in GitHub Desktop.
Save omikun/9dcdbdbc205adeacdafbc616fba88446 to your computer and use it in GitHub Desktop.
Scythe hex board init code
using System.IO;
using System;
//data structure for hex grid
class HexLink
{
public Hex link = null;
public bool river = false;
public HexLink(Hex h=null, bool r=false)
{
link = h;
river = r;
}
}
class Hex
{
public HexLink TopLeft = new HexLink();
public HexLink TopRight = new HexLink();
public HexLink Left = new HexLink();
public HexLink Right = new HexLink();
public HexLink BottomLeft = new HexLink();
public HexLink BottomRight = new HexLink();
public string Resource = "Lake";
public bool Tunnel = false;
public bool Encounter = false;
public Hex (string r, bool t=false, bool e=false)
{
Resource = r;
Tunnel = t;
Encounter = e;
}
public void PrintConns()
{
string str = "";
str += "TL: " + TryPrintConn(ref TopLeft);
str += "RL: " + TryPrintConn(ref TopRight);
str += "L: " + TryPrintConn(ref Left);
str += "R: " + TryPrintConn(ref Right);
str += "BL: " + TryPrintConn(ref BottomLeft);
str += "BR: " + TryPrintConn(ref BottomRight);
Console.WriteLine(Resource + "->" + str);
}
public string TryPrintConn(ref HexLink conn)
{
if(conn.link != null)
return conn.link.Resource + ", ";
else
return " ,";
}
}
class Board
{
public Hex[][] board = new Hex[8][];
public void PrintConn()
{
foreach(var row in board)
{
foreach(var hex in row)
{
hex.PrintConns();
}
}
}
public void InitBoard()
{
board[0] = new Hex[6];
board[1] = new Hex[7];
board[2] = new Hex[6];
board[3] = new Hex[7];
board[4] = new Hex[7];
board[5] = new Hex[6];
board[6] = new Hex[6];
board[7] = new Hex[1];
string[][] rows = new string[8][];
rows[0] = new string[]{"Mountain", "Farm", "Village", "Forest", "Tundra", "Village"};
rows[1] = new string[]{"Lake", "Tundra", "Lake", "Tundra", "Mountain", "Farm", "Farm"};
rows[2] = new string[]{"Forest", "Mountain", "Forest", "Lake", "Forest", "Village"};
rows[3] = new string[]{"Farm", "Village", "Lake", "Factory", "Mountain", "Tundra", "Mountain"};
rows[4] = new string[]{"Forest", "Forest", "Farm", "Tundra", "Lake", "Village", "Lake"};
rows[5] = new string[]{"Mountain", "Village", "Village", "Tundra", "Forest", "Mountain", "Tundra"};
rows[6] = new string[]{"Tundra", "Lake", "Farm", "Mountain", "Village", "Farm"};
rows[7] = new string[]{"Village"};
//init tile name
for(int row = 0; row < 8; row++)
{
string names = "";
for(int col = 0; col < board[row].Length; col++)
{
board[row][col] = new Hex(rows[row][col]);
names += (rows[row][col] + ", ");
}
Console.WriteLine(row.ToString() + " " + names);
}
Console.WriteLine("Special hexes");
//init special hexes
board[0][2].Encounter = true;
board[1][1].Encounter = true;
board[1][3].Tunnel = true;
board[1][4].Encounter = true;
board[1][6].Encounter = true;
board[2][1].Tunnel = true;
board[2][4].Tunnel = true;
board[3][1].Encounter = true;
board[3][5].Encounter = true;
board[4][0].Encounter = true;
board[4][2].Tunnel = true;
board[4][5].Tunnel = true;
board[5][1].Encounter = true;
board[5][2].Encounter = true;
board[5][3].Tunnel = true;
board[5][5].Encounter = true;
board[6][3].Encounter = true;
Console.WriteLine("horizontal links hexes");
//init horiz links
for(int row = 0; row < 6; row++)
{
string names = "";
for(int col = 0; col < board[row].Length-1; col++)
{
board[row][col].Right.link = board[row][col+1];
board[row][col+1].Left.link = board[row][col];
names += (rows[row][col] + ", ");
}
Console.WriteLine(row.ToString() + " " + names);
}
//init diag links
Console.WriteLine("diag links hexes");
ConnectToLowerLeft(0);
ConnectToLowerRight(1);
ConnectToLowerLeft(2);
ConnectToLowerLeft(3);
ConnectToLowerRight(4);
ConnectToLowerRight(5);
//last row
}
void ConnectToLowerLeft(int row)
{
Console.WriteLine("ConnectToLowerLeft row: " + row);
int curRowLength = board[row].Length;
int nextRowLength = board[row+1].Length;
for(int col = 0; col < curRowLength; col++)
{
Console.WriteLine("col: " + col);
board[row][col].BottomLeft.link = board[row+1][col];
board[row+1][col].TopRight.link = board[row][col];
if (col+1 < nextRowLength-1)
{
board[row][col].BottomRight.link = board[row+1][col+1];
board[row+1][col+1].TopLeft.link = board[row][col];
}
}
}
int NumCells(int row)
{
return board[row].Length-1;
}
void ConnectToLowerRight(int row)
{
Console.WriteLine("ConnectToLowerRight row: " + row);
//connect first hex
int col = 0;
board[row][col].BottomRight.link = board[row+1][col]; //2
board[row+1][col].TopLeft.link = board[row][col]; //4
for( col = 1; col < NumCells(row); col++)
{
if (col > 0)
{
board[row][col].BottomLeft.link = board[row+1][col-1]; //1
board[row+1][col-1].TopRight.link = board[row][col]; //3
}
if (col <= NumCells(row+1))
{
board[row][col].BottomRight.link = board[row+1][col]; //2
board[row+1][col].TopLeft.link = board[row][col]; //4
}
}
//connect last hex
col = board[row].Length-1;
board[row][col].BottomLeft.link = board[row+1][col-1]; //1
board[row+1][col-1].TopRight.link = board[row][col]; //3
}
}
class Player {
int stars = 0;
int coins = 0;
int powers = 0;
int hearts = 0;
//upgrades
//enlistment
//buildings
//mech deployed
//workers made
//battles won
public bool Win()
{
return stars == 6;
}
public void Turn()
{
}
}
class Program {
static Player[] players = new Player[4];
static bool PlayerWon()
{
foreach(var player in players)
{
if (player.Win())
return true;
}
return false;
}
static void Main()
{
Console.WriteLine("Hello, World!");
Board board = new Board();
board.InitBoard();
board.PrintConn();
//start a player
for(int i=0; i < players.Length; i++)
{
players[i] = new Player();
}
//setup player
//gameplay loop
foreach (var player in players)
{
player.Turn();
if (player.Win())
break;
}
//count scores
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment