Compare commits
9 commits
Author | SHA1 | Date | |
---|---|---|---|
|
0ab3da69fc | ||
|
f17b3a17fe | ||
|
89fc5302ea | ||
|
a1e425258d | ||
|
3b5196830c | ||
|
b01c93a000 | ||
|
c9fb6896d2 | ||
|
f71bd4b1d6 | ||
|
11a8873dc5 |
11 changed files with 191 additions and 7 deletions
|
@ -49,6 +49,7 @@ else()
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
install( FILES "${CMAKE_BINARY_DIR}/ttrts.6" DESTINATION ${MANPAGE_LOC} )
|
install( FILES "${CMAKE_BINARY_DIR}/ttrts.6" DESTINATION ${MANPAGE_LOC} )
|
||||||
|
install( FILES "${CMAKE_SOURCE_DIR}/api/lua/ttrts.lua" DESTINATION share/lua/5.1/ )
|
||||||
|
|
||||||
# Subprojects
|
# Subprojects
|
||||||
add_subdirectory( source )
|
add_subdirectory( source )
|
||||||
|
|
|
@ -13,12 +13,13 @@ TTRTS is from the ground up designed to be a fun way to practice programming. An
|
||||||
#### Requirements
|
#### Requirements
|
||||||
* CMake - our build system uses cmake
|
* CMake - our build system uses cmake
|
||||||
* Linux/OSX - currently no support for Windows, tracked with [Issue #9](https://github.com/mdiluz/ttrts/issues/9)
|
* Linux/OSX - currently no support for Windows, tracked with [Issue #9](https://github.com/mdiluz/ttrts/issues/9)
|
||||||
|
* perl 5.0 or newer - for the launch script
|
||||||
|
|
||||||
#### To Build
|
#### To Build
|
||||||
$ git clone https://github.com/mdiluz/ttrts.git
|
$ git clone https://github.com/mdiluz/ttrts.git
|
||||||
$ cd ttrts
|
$ cd ttrts
|
||||||
$ ./bootstrap.sh
|
$ ./bootstrap.sh
|
||||||
$ ./ttrts # To launch binary and display usage
|
$ man ttrts # for full usage and guide
|
||||||
|
|
||||||
-----------------------------------------------------------
|
-----------------------------------------------------------
|
||||||
## Development
|
## Development
|
||||||
|
@ -80,6 +81,6 @@ TTRTS is from the ground up designed to be a fun way to practice programming. An
|
||||||
-----------------------------------------------------------
|
-----------------------------------------------------------
|
||||||
## Further Information
|
## Further Information
|
||||||
|
|
||||||
See the ttrts binary [readme](source/ttrts/README.md) for full usage and game rules
|
See the ttrts [README](source/README.md) for full usage and game rules
|
||||||
|
|
||||||
See [ttrts-players](https://github.com/mdiluz/ttrts-players) for examples of AIs
|
See [ttrts-players](https://github.com/mdiluz/ttrts-players) for examples of AIs
|
||||||
|
|
12
api/java/ttrts.java
Normal file
12
api/java/ttrts.java
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
|
||||||
|
|
||||||
|
class ttrts
|
||||||
|
{
|
||||||
|
|
||||||
|
public static void main(String[] args)
|
||||||
|
{
|
||||||
|
System.out.println("I'm the ttrts Java module");
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
153
api/lua/ttrts.lua
Executable file
153
api/lua/ttrts.lua
Executable file
|
@ -0,0 +1,153 @@
|
||||||
|
#! /usr/bin/lua
|
||||||
|
|
||||||
|
-- need socket for server communications
|
||||||
|
require "socket"
|
||||||
|
|
||||||
|
local ttrts = {}
|
||||||
|
|
||||||
|
--[[ Attempt to connect to the server ]]
|
||||||
|
function ttrts.ConnectToHost(host)
|
||||||
|
|
||||||
|
|
||||||
|
ttrts.socket = socket.connect( host, 11715 )
|
||||||
|
if not ttrts.socket then error("Failed to connect to " .. host .. " on port 11715") end
|
||||||
|
|
||||||
|
-- Porform the hanshake
|
||||||
|
local line = ttrts.socket:receive('*l')
|
||||||
|
|
||||||
|
local player, name = string.match(line, "player (%d+) name ([%a%d]+)")
|
||||||
|
|
||||||
|
-- bail out if handshake information failed
|
||||||
|
assert( player and name , "Handshake failed with incorrect player and name")
|
||||||
|
|
||||||
|
-- return the handshake line with a new line (removed by the *l call to receive) and string end
|
||||||
|
ttrts.socket:send( line .. "\n" .. "\0" )
|
||||||
|
|
||||||
|
return player, name
|
||||||
|
end
|
||||||
|
|
||||||
|
-- [[ Recieve gamestate info ]]
|
||||||
|
function ttrts.GetStateFromHost()
|
||||||
|
|
||||||
|
if not ttrts.socket then error("ttrts.socket must be set") end
|
||||||
|
|
||||||
|
function newLine()
|
||||||
|
return ttrts.socket:receive('*l')
|
||||||
|
end
|
||||||
|
|
||||||
|
local line = ""
|
||||||
|
local state = {}
|
||||||
|
|
||||||
|
-- INVESTIGATE WHY THIS IS NEEDED
|
||||||
|
newLine()
|
||||||
|
|
||||||
|
local thename = newLine()
|
||||||
|
state.name = string.match( thename, "NAME:([%a%d]+)" )
|
||||||
|
assert( state.name, "Gamestate file format missmatch (no name)")
|
||||||
|
|
||||||
|
state.size = {}
|
||||||
|
local sizes = newLine()
|
||||||
|
state.size.x, state.size.y = string.match( sizes, "SIZE:%[(%d+),(%d+)%]" )
|
||||||
|
assert( state.size.x and state.size.y , "Gamestate file format missmatch (size failure)")
|
||||||
|
|
||||||
|
state.turn = string.match( newLine(), "TURN:(%d+)" )
|
||||||
|
assert( state.turn, "Gamestate file format missmatch (no turn)")
|
||||||
|
|
||||||
|
-- Get the wall line
|
||||||
|
state.walls = {}
|
||||||
|
local wallline = newLine()
|
||||||
|
|
||||||
|
assert(string.match( wallline, "WALL:"), "Gamestate file format missmatch (no wall line)")
|
||||||
|
|
||||||
|
-- Grab all walls on the line
|
||||||
|
for wallstring in string.gmatch(wallline, "%[%d+,%d+%]") do
|
||||||
|
local wall = {}
|
||||||
|
wall.x, wall.y = string.match( wallstring, "%[(%d+),(%d+)%]" )
|
||||||
|
table.insert(state.walls,wall)
|
||||||
|
end
|
||||||
|
|
||||||
|
assert( newLine() == "~~~~", "Gamestate file format missmatch (missing ~~~~)" )
|
||||||
|
|
||||||
|
-- get the units
|
||||||
|
state.units = {}
|
||||||
|
|
||||||
|
local unitline = newLine()
|
||||||
|
while unitline ~= "END" do
|
||||||
|
|
||||||
|
local unit = {}
|
||||||
|
unit.pos = {}
|
||||||
|
|
||||||
|
-- Parse the unit line
|
||||||
|
unit.id, unit.player, unit.vis, unit.dir, unit.pos.x, unit.pos.y =
|
||||||
|
string.match( unitline, "UNIT:(%d+) pl:(%d+) vs:([^%s]+) dr:(%a+) ps:%[(%d+),(%d+)%]")
|
||||||
|
|
||||||
|
assert(unit.id and unit.player and unit.vis and unit.dir and unit.pos.x and unit.pos.y, "gamestate file format missmatch (error with unit)")
|
||||||
|
|
||||||
|
table.insert(state.units,unit)
|
||||||
|
|
||||||
|
unitline = newLine()
|
||||||
|
end
|
||||||
|
|
||||||
|
assert(unitline == "END", "Gamestate file format missmatch (didn't end in END)")
|
||||||
|
|
||||||
|
return state
|
||||||
|
end
|
||||||
|
|
||||||
|
-- [[ Get Random Orders from gamestate for a particular player ]]
|
||||||
|
function ttrts.GetRandomOrders( id, state )
|
||||||
|
|
||||||
|
local orders = ""
|
||||||
|
local possibleorders = { "F", "L", "R", "A" }
|
||||||
|
|
||||||
|
local units = state.units
|
||||||
|
for key,unit in pairs(units) do
|
||||||
|
if unit.id == id then
|
||||||
|
local order = "F" -- TODO MAKE RANDOM
|
||||||
|
orders = orders .. "ORDER:" .. order .. " id:" .. tostring(id) .. "\n"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
orders = orders .. "END\n"
|
||||||
|
|
||||||
|
return orders
|
||||||
|
end
|
||||||
|
|
||||||
|
-- [[ Send the orders to the server through the socket ]]
|
||||||
|
function ttrts.SendOrdersToHost( orders )
|
||||||
|
assert( string.match(orders,"END"), "Cannot send orders without END" )
|
||||||
|
ttrts.socket:send( orders .. "\0" )
|
||||||
|
end
|
||||||
|
|
||||||
|
-- [[ using method from http://lua-users.org/wiki/AlternativeGetOpt ]]
|
||||||
|
function ttrts.getopt( arg, options )
|
||||||
|
local tab = {}
|
||||||
|
for k, v in ipairs(arg) do
|
||||||
|
if string.sub( v, 1, 2) == "--" then
|
||||||
|
local x = string.find( v, "=", 1, true )
|
||||||
|
if x then tab[ string.sub( v, 3, x-1 ) ] = string.sub( v, x+1 )
|
||||||
|
else tab[ string.sub( v, 3 ) ] = true
|
||||||
|
end
|
||||||
|
elseif string.sub( v, 1, 1 ) == "-" then
|
||||||
|
local y = 2
|
||||||
|
local l = string.len(v)
|
||||||
|
local jopt
|
||||||
|
while ( y <= l ) do
|
||||||
|
jopt = string.sub( v, y, y )
|
||||||
|
if string.find( options, jopt, 1, true ) then
|
||||||
|
if y < l then
|
||||||
|
tab[ jopt ] = string.sub( v, y+1 )
|
||||||
|
y = l
|
||||||
|
else
|
||||||
|
tab[ jopt ] = arg[ k + 1 ]
|
||||||
|
end
|
||||||
|
else
|
||||||
|
tab[ jopt ] = true
|
||||||
|
end
|
||||||
|
y = y + 1
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return tab
|
||||||
|
end
|
||||||
|
|
||||||
|
return ttrts
|
|
@ -3,7 +3,7 @@ use strict;
|
||||||
use warnings;
|
use warnings;
|
||||||
|
|
||||||
our $ttrts_perlai_versioncompat_major = 0;
|
our $ttrts_perlai_versioncompat_major = 0;
|
||||||
our $ttrts_perlai_versioncompat_minor = 3;
|
our $ttrts_perlai_versioncompat_minor = 4;
|
||||||
|
|
||||||
our $headerDelimiter="~~~~";
|
our $headerDelimiter="~~~~";
|
||||||
|
|
||||||
|
|
9
api/python/ttrts.py
Executable file
9
api/python/ttrts.py
Executable file
|
@ -0,0 +1,9 @@
|
||||||
|
#! /usr/bin/python
|
||||||
|
# python ttrts module
|
||||||
|
|
||||||
|
# Import the python regex module
|
||||||
|
import re
|
||||||
|
|
||||||
|
headerRegex = re.compile(
|
||||||
|
"==== ttrts v(\\d+)\\.(\\d+)\\.(\\d+)+ ====\nNAME:(.+)\nSIZE:\\[(\\d+),(\\d+)\\]\nTURN:(\\d+)\n(WALL:.*?)"
|
||||||
|
,re.MULTILINE )
|
5
api/ruby/ttrts.rb
Executable file
5
api/ruby/ttrts.rb
Executable file
|
@ -0,0 +1,5 @@
|
||||||
|
#!/usr/bin/ruby
|
||||||
|
|
||||||
|
module TTRTS
|
||||||
|
|
||||||
|
end
|
|
@ -41,4 +41,4 @@ $res = system("ttrts-client $host") if $client and $host;
|
||||||
$res = system("ttrts-server $map") if $server and $map;
|
$res = system("ttrts-server $map") if $server and $map;
|
||||||
$res = system("ttrts-local $map") if not $server and not $client and $map;
|
$res = system("ttrts-local $map") if not $server and not $client and $map;
|
||||||
|
|
||||||
return $res
|
exit $res
|
||||||
|
|
|
@ -108,7 +108,10 @@ void PerformServerHandshake(const ClientInfo &client, const std::string &game)
|
||||||
|
|
||||||
// Verify handshake
|
// Verify handshake
|
||||||
if ( std::string(buffer) != std::string(handshake) )
|
if ( std::string(buffer) != std::string(handshake) )
|
||||||
|
{
|
||||||
|
std::cerr<<"Handshake was \""<<handshake<<"\" but recieved \""<<buffer<<"\""<<std::endl;
|
||||||
fatal_error("Error in client handshake");
|
fatal_error("Error in client handshake");
|
||||||
|
}
|
||||||
|
|
||||||
std::clog<<"TTRTS: Success on handshake with player "<<(int)client.player<< std::endl;
|
std::clog<<"TTRTS: Success on handshake with player "<<(int)client.player<< std::endl;
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,7 +16,7 @@
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
#define TTRTS_HANDSHAKE_FORMAT "player %u name %s"
|
#define TTRTS_HANDSHAKE_FORMAT "player %u name %s\n"
|
||||||
|
|
||||||
//======================================================================================================================
|
//======================================================================================================================
|
||||||
// Structs for net management
|
// Structs for net management
|
||||||
|
|
|
@ -52,7 +52,7 @@ std::string GetStringFromGame( const CTTRTSGame& game )
|
||||||
state += '\n';
|
state += '\n';
|
||||||
state += GAME_HEADER_DELIMITER;
|
state += GAME_HEADER_DELIMITER;
|
||||||
state += units;
|
state += units;
|
||||||
state += "END";
|
state += "END\n";
|
||||||
|
|
||||||
return state;
|
return state;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue