Swiftpack.co - Package - matthesjh/sc19-swift-client

Swift client for Software-Challenge Germany 2018/2019

Build Status

This package contains a simple client written in Swift for Software-Challenge Germany 2018/2019.

The game of the contest year 2018/2019 is called Piranhas. It is played on a board with 10x10 fields. The goal of the game is to unite his piranhas to a single swarm. The complete documentation of the game rules and the XML communication with the game server can be found here.

Usage

Please make sure that you have installed the latest Swift toolchain (or at least version 4.2) on your operating system. The latest version of Swift can be found here.

To build and run the executable of the simple client, use the run command of the Swift Package Manager.

swift run

If you want to use e.g. another host address or port for the simple client, then you can pass additional arguments to the run command of the Swift Package Manager. Please note that you need to specify the name of the executable when using additional arguments.

swift run simple-client -h 127.0.0.1 -p 13050

The simple client supports the following command-line arguments.

Usage: simple-client [options]
  -h, --host:
      The IP address of the host to connect to (default: 127.0.0.1).
  -p, --port:
      The port used for the connection (default: 13050).
  -r, --reservation:
      The reservation code to join a prepared game.
  -s, --strategy:
      The strategy used for the game.
  --help:
      Print this help message.

Creating an archive for upload

In order to use the simple client on the competition system (a.k.a. Wettkampfsystem), a zip archive must be created that contains a start script and the compiled executable. To create such an archive, run the following commands on the terminal.

chmod u+x scripts/zip-client.sh
scripts/zip-client.sh

The resulting archive (simple-client.zip) can then be uploaded to the competition system. Please make sure that you select the start script (start-client.sh) as the main file in the uploading process.

Note: The above script (zip-client.sh) builds the client with the release configuration and calls the Swift compiler with the -O flag to optimize the executable for speed.

Customizing the logic

To customize the logic of the simple client to your own needs, simply adjust the onMoveRequested() method in the SCGameLogic.swift class.

func onMoveRequested() -> SCMove? {
    print("*** A move is requested by the game server!")

    // TODO: Add your own logic here.

    return self.gameState.possibleMoves().randomElement()
}

If you want to return e.g. the last possible move, the method can be changed as follows.

func onMoveRequested() -> SCMove? {
    print("*** A move is requested by the game server!")

    return self.gameState.possibleMoves().last
}

In addition to the default logic class, you can also implement your own logic classes. To use one of your own logic classes, the simple client offers the possibility to select a strategy (logic class) based on the value of a command-line argument (-s or --strategy). By default, this feature is disabled. To enable the feature, create a logic instance based on the strategy property of the SCGameHandler.swift class. This can be done by replacing the existing code line with a switch-statement like the following.

switch self.strategy {
    case "winner":
        self.delegate = SCWinnerLogic(player: self.playerColor)
    case "crazy":
        self.delegate = SCCrazyGameLogic(player: self.playerColor)
    case "another_logic":
        self.delegate = AnotherLogic(player: self.playerColor)
    // ...
    default:
        self.delegate = SCGameLogic(player: self.playerColor)
}

Renaming the client

If you want to change the name of the simple client, you have to adjust the target name in the Package.swift file and the directory name in the Sources folder. Furthermore the EXECUTABLE_NAME variable in the shell scripts needs to be changed.

Github

link
Stars: 3
Help us keep the lights on

Dependencies

Used By

Total: 0

Releases

v1.0.0 - Oct 5, 2018

  • First release