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()
Import the Game class from Werewolf.server.logic module
Set the number of players
Configure the identity list (see below)
Start listening for players
Activate the game
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:
Villager, Wolf, the value should be at least 1
Predictor, Witch, Hunter, Guard, Idiot, KingOfWerewolves, WhiteWerewolf, the value should be at most 1.
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:
hostIP: the IP address of the server, both IPv4 addresses and IPv6 addresses are accepted.
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.
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.
Server Side Configuration
Here is a sample configuration:
Game
class fromWerewolf.server.logic
moduleNetwork 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:
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:Villager
,Wolf
, the value should be at least 1Predictor
,Witch
,Hunter
,Guard
,Idiot
,KingOfWerewolves
,WhiteWerewolf
, the value should be at most 1.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 informationClient Side Configuration
Here is a sample configuration:
Function
launchClient
accepts the following parameters:hostIP
: the IP address of the server, both IPv4 addresses and IPv6 addresses are accepted.hostPort
: the listening port of the server.