HuangFuSL / Werewolf

The final project of Computer Network in 2020A
MIT License
1 stars 3 forks source link

How to Play #19

Open HuangFuSL opened 3 years ago

HuangFuSL commented 3 years ago

Server Side Configuration

Here is a sample configuration:

from Werewolf.misc.preset12 import Villager4Wolf3PredictorWitchHunterGuardWhite
from Werewolf.server.logic import Game

if __name__ == "__main__":
    playerCount: int = 12
    print('the number of players is: %d' % playerCount)

    # initialize a new game
    game = Game(playerCount)
    identityList = Villager4Wolf3PredictorWitchHunterGuardWhite
    game.setIdentityList(**identityList)
    game.startListening()
    game.activate()
    # start the game
    game.launch()
  1. Import the Game class from Werewolf.server.logic module
  2. Set the number of players
  3. Configure the identity list (see below)
  4. Start listening for players
  5. Activate the game
  6. Launch the game

Network configuration

The server supports both IPv4 and IPv6. The default port used for the game is 21567 and 21568. The listening IP address and port can be customized by specifying parameters:

game = Game(playerCount, ipv4='localhost', ipv6='::1', port='25565')

Identity configuration

Supported identities: villagers, wolves, predictor, witch, hunter, guard, idiot, king of werewolf (狼王), white werewolf (白狼王). Method setIdentityList accepts a series of corresponding parameters to initialize the list. Accepted parameters are:

If the parameters given does not match with the number of players, the game CANNOT be activated.

We have provided several presets in the module Werewolf.misc. Refer to the code directory for more information

Client Side Configuration

Here is a sample configuration:

from Werewolf.client import launchClient

if __name__ == "__main__":
    serverAddr = input("Please enter the IP address of the server:\n")
    if not serverAddr:
        serverAddr = "localhost"
    try:
        serverPort = int(input("Please enter the port of the server:\n"))
    except:
        serverPort = 21567
    launchClient(serverAddr, serverPort)

Function launchClient accepts the following parameters:

HuangFuSL commented 3 years ago
  1. For wolves, pressing Ctrl+C is regarded as self explosion (自爆), this action is only available for wolves in day. Self-explosions are broadcasted to all of the players.
  2. A white werewolf can kill a person when Ctrl+C is pressed.

This is almost the hardest part in the project. :smile: Another key feature is the instant-messaging for wolves at night.

jw-liu2000 commented 3 years ago

tql