Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/python -tt
- # coding: utf-8
- import random
- import time
- class Player:
- def __init__(self, mafia, can_kill, blocker, defence, healer):
- self.mafia = mafia
- self.can_kill = can_kill
- self.blocker = blocker
- self.defence = defence
- self.healer = healer
- alive = 'yes'
- healed = 'no'
- blocked = 'no'
- moved = 'no'
- kills = 0
- #def __repr__(self):
- # return "Player(%s, %s, %s)" % (self.alive, self.mafia, self.can_kill)
- def main():
- number_of_players = 20
- players = [Player('no', 'no', 'no', 'no', 'no') for i in range(number_of_players)]
- # mafia can_kill blocker defence healer
- #mafia
- players[0] = Player('yes', 'no', 'no', 'yes', 'no')
- players[1] = Player('yes', 'yes', 'yes', 'no', 'no')
- players[2] = Player('yes', 'yes', 'no', 'no', 'yes')
- players[3] = Player('yes', 'yes', 'no', 'no', 'no')
- players[4] = Player('yes', 'yes', 'no', 'no', 'no')
- #maniac
- players[5] = Player('no', 'yes', 'no', 'no', 'no')
- players[6] = Player('no', 'yes', 'no', 'no', 'no')
- #blocker
- players[7] = Player('no', 'no', 'yes', 'no', 'no')
- #healer
- players[8] = Player('no', 'no', 'no', 'no', 'yes')
- #def_towns
- players[9] = Player('no', 'no', 'no', 'yes', 'no')
- players[10]= Player('no', 'no', 'no', 'yes', 'no')
- game(players, number_of_players)
- def game(players, number_of_players):
- days_count = 0
- while True:
- killed_list = []
- alive_list = []
- alive_count = 0
- mafia_count = 0
- maniac_count = 0
- player_count = 0
- for player in players:
- if player.alive == 'yes':
- alive_count += 1
- alive_list.append(player_count)
- if player.mafia == 'yes':
- mafia_count += 1
- if player.mafia == 'no' and player.can_kill == 'yes':
- maniac_count += 1
- player_count += 1
- print "-------------------------------------------------------------------"
- print "%s день" % days_count
- print "Живых: %s" % alive_count
- print "Город: %s" % (alive_count - mafia_count - maniac_count)
- print "Мафов: %s" % mafia_count
- print "Маньяков: %s" % maniac_count
- if alive_count - mafia_count <= mafia_count and maniac_count == 0:
- print 'mafia wins'
- break
- if mafia_count == 0 and maniac_count == 0:
- print 'town wins'
- break
- if mafia_count == 0 and maniac_count == 1 and alive_count <= 2:
- print 'maniac wins'
- break
- for player in players:
- player.moved = 'no'
- player.blocked = 'no'
- player.healed = 'no'
- #ход блокеров
- player_count = 0
- for player in players:
- if player.alive == 'yes' and player.blocked == 'no' and player.moved == 'no':
- if player.mafia == 'no':
- if player.blocker == 'yes':
- block = 0
- n = 0
- while block == 0 or n > 1000:
- n += 1
- blocked = random.randint(0, number_of_players-1)
- if players[blocked].alive == 'yes' and blocked != player_count:
- block = 1
- players[blocked].blocked = 'yes'
- # players[player_count].moved = 'yes'
- print 'городской блокер %s блокирует игрока номер %s' % (player_count, blocked)
- elif player.mafia == 'yes':
- if player.blocker == 'yes':
- if mafia_count != 2:
- block = 0
- n = 0
- while block == 0 or n > 1000:
- n += 1
- blocked = random.randint(0, number_of_players-1)
- if players[blocked].alive == 'yes' and players[blocked].mafia == 'no':
- block = 1
- players[blocked].blocked = 'yes'
- if mafia_count != 1:
- players[player_count].moved = 'yes'
- print 'маф блокер %s блокирует игрока номер %s' % (player_count, blocked)
- player_count += 1
- #ход лекарей
- player_count = 0
- for player in players:
- if player.alive == 'yes' and player.blocked == 'no' and player.moved == 'no':
- if player.mafia == 'no':
- if player.healer == 'yes':
- heal = 0
- n = 0
- while heal == 0 or n > 1000:
- n += 1
- healed = random.randint(0, number_of_players-1)
- if players[healed].alive == 'yes' and healed != player_count:
- heal = 1
- players[healed].healed = 'yes'
- # players[player_count].moved = 'yes'
- print 'городской лекарь %s лечит игрока номер %s' % (player_count, healed)
- elif player.mafia == 'yes':
- if player.healer == 'yes':
- heal = 0
- n = 0
- while heal == 0 or n > 1000:
- n += 1
- healed = random.randint(0, number_of_players-1)
- if players[healed].alive == 'yes' and players[healed].mafia == 'yes':
- heal = 1
- players[healed].healed = 'yes'
- players[player_count].moved = 'yes'
- print 'маф лекарь %s лечит игрока номер %s' % (player_count, healed)
- player_count += 1
- #ход маньяков
- player_count = 0
- for player in players:
- if player.alive == 'yes' and player.blocked == 'no' and player.moved == 'no' and player.mafia == 'no' and player.can_kill == 'yes':
- kill = 0
- n = 0
- while kill == 0 or n > 1000:
- n += 1
- killed = random.randint(0, number_of_players-1)
- if players[killed].alive == 'yes' and killed != player_count:
- kill = 1
- if players[killed].defence == 'no' and players[killed].healed == 'no':
- killed_list.append(killed)
- elif players[killed].defence == 'yes':
- players[killed].defence = 'no'
- # players[player_count].moved = 'yes'
- print "Номер убивающего маньяка(должен быть 5-6): %s, идет убивать: %s" % (player_count, killed)
- player_count += 1
- #ход оставшихся мафов
- mafia_kill = 0
- player_count = 0
- for player in players:
- if player.alive == 'yes' and player.blocked == 'no' and player.moved == 'no' and player.mafia == 'yes' and player.can_kill == 'yes':
- if mafia_kill == 0: # убивала ли уже мафия
- kill = 0
- n = 0
- while kill == 0 or n > 1000:
- n += 1
- killed = random.randint(0, number_of_players-1)
- if players[killed].alive == 'yes' and players[killed].mafia == 'no':
- kill = 1
- if players[killed].defence == 'no' and players[killed].healed =='no':
- killed_list.append(killed)
- elif players[killed].defence == 'yes':
- players[killed].defence = 'no'
- mafia_kill = 1
- players[player_count].moved = 'yes'
- print "Номер убивающего мафа(должен быть 1-4): %s, идет убивать: %s" % (player_count, killed)
- player_count += 1
- print killed_list
- print alive_list
- for kill in killed_list:
- players[kill].alive = 'no'
- end_alive_count = 0
- for player in players:
- if player.alive == 'yes':
- end_alive_count += 1
- kill_count = alive_count - end_alive_count
- print "***"
- print "Убийств ночью: %s" % kill_count
- days_count += 1
- # This is the standard boilerplate that calls the main() function.
- if __name__ == '__main__':
- main()
Advertisement
Add Comment
Please, Sign In to add comment