Пример #1
0
def runGame():
    currentState = INITIAL_STATE
    print('The Gamemaster says, "Players, introduce yourselves."')
    print('     (Playing X:) ' + player1.introduce())
    print('     (Playing O:) ' + player2.introduce())

    if USE_HTML:
        gameToHTML.startHTML(player1.nickname(), player2.nickname(), GAME_TYPE,
                             1)
    try:
        p1comment = player1.prepare(INITIAL_STATE, K, 'X', player2.nickname())
    except:
        report = 'Player 1 (' + player1.nickname(
        ) + ' failed to prepare, and loses by default.'
        print(report)
        if USE_HTML: gameToHTML.reportResult(report)
        report = 'Congratulations to Player 2 (' + player2.nickname() + ')!'
        print(report)
        if USE_HTML: gameToHTML.reportResult(report)
        if USE_HTML: gameToHTML.endHTML()
        return
    try:
        p2comment = player2.prepare(INITIAL_STATE, K, 'O', player1.nickname())
    except:
        report = 'Player 2 (' + player2.nickname(
        ) + ' failed to prepare, and loses by default.'
        print(report)
        if USE_HTML: gameToHTML.reportResult(report)
        report = 'Congratulations to Player 1 (' + player1.nickname() + ')!'
        print(report)
        if USE_HTML: gameToHTML.reportResult(report)
        if USE_HTML: gameToHTML.endHTML()
        return
        return

    print('The Gamemaster says, "Let\'s Play!"')
    print('The initial state is...')

    currentRemark = "The game is starting."
    if USE_HTML: gameToHTML.stateToHTML(currentState)

    XsTurn = True
    name = None
    global FINISHED
    FINISHED = False
    turnCount = 0
    printState(currentState)
    while not FINISHED:
        who = currentState[1]
        if XsTurn:
            playerResult = player1.makeMove(currentState, currentRemark,
                                            TIME_PER_MOVE)
            name = player1.nickname()
            XsTurn = False
        else:
            playerResult = player2.makeMove(currentState, currentRemark,
                                            TIME_PER_MOVE)
            name = player2.nickname()
            XsTurn = True
        moveAndState, currentRemark = playerResult
        if moveAndState == None:
            FINISHED = True
            continue
        move, currentState = moveAndState
        moveReport = "Move is by " + who + " to " + str(move)
        print(moveReport)
        utteranceReport = name + ' says: ' + currentRemark
        print(utteranceReport)
        if USE_HTML: gameToHTML.reportResult(moveReport)
        if USE_HTML: gameToHTML.reportResult(utteranceReport)
        possibleWin = winTesterForK(currentState, move, K)
        if possibleWin != "No win":
            FINISHED = True
            printState(currentState)
            if USE_HTML: gameToHTML.stateToHTML(currentState, finished=True)
            print(possibleWin)
            if USE_HTML: gameToHTML.reportResult(possibleWin)
            if USE_HTML: gameToHTML.endHTML()
            return
        printState(currentState)
        if USE_HTML: gameToHTML.stateToHTML(currentState)
        turnCount += 1
        #if turnCount == 9: FINISHED=True
    printState(currentState)
    if USE_HTML: gameToHTML.stateToHTML(currentState)
    who = currentState[1]
    print("Game over.")
    if USE_HTML: gameToHTML.reportResult("Game Over; it's a draw")
    if USE_HTML: gameToHTML.endHTML()
Пример #2
0
def runGame():
    currentState = INITIAL_STATE
    print(INITIAL_STATE)
    print('The Gamemaster says, "Players, introduce yourselves."')
    print('     (Playing X:) '+player1.introduce())
    print('     (Playing O:) '+player2.introduce())

    if USE_HTML:
        gameToHTML.startHTML(player1.nickname(), player2.nickname(), NAME, 1)
    try:
        p1comment = player1.prepare(INITIAL_STATE, K, 'X', player2.nickname())
    except:
        report = 'Player 1 ('+player1.nickname()+' failed to prepare, and loses by default.'
        print(report)
        if USE_HTML: gameToHTML.reportResult(report)
        report = 'Congratulations to Player 2 ('+player2.nickname()+')!'
        print(report)
        if USE_HTML: gameToHTML.reportResult(report)
        if USE_HTML: gameToHTML.endHTML()
        return
    try:
        p2comment = player2.prepare(INITIAL_STATE, K, 'O', player1.nickname())
    except:
        report = 'Player 2 ('+player2.nickname()+' failed to prepare, and loses by default.'
        print(report)
        if USE_HTML: gameToHTML.reportResult(report)
        report = 'Congratulations to Player 1 ('+player1.nickname()+')!'
        print(report)
        if USE_HTML: gameToHTML.reportResult(report)
        if USE_HTML: gameToHTML.endHTML()
        return
        return
    
                    
    print('The Gamemaster says, "Let\'s Play!"')
    print('The initial state is...')

    currentRemark = "The game is starting."
    if USE_HTML: gameToHTML.stateToHTML(currentState)

    XsTurn = True
    name = None
    global FINISHED
    FINISHED = False
    turnCount = 0
    printState(currentState)
    while not FINISHED:
        who = currentState[1]
        global CURRENT_PLAYER
        CURRENT_PLAYER = who
        if XsTurn:
            playerResult = timeout(player1.makeMove,args=(currentState, currentRemark, TIME_PER_MOVE), kwargs={}, timeout_duration=TIME_PER_MOVE, default=(None,"I give up!"));
            name = player1.nickname()
            XsTurn = False
            #print(playerResult)
        else:
            playerResult = timeout(player2.makeMove,args=(currentState, currentRemark, TIME_PER_MOVE), kwargs={}, timeout_duration=TIME_PER_MOVE, default=(None,"I give up!"));
            name = player2.nickname()
            XsTurn = True
            #print(playerResult)
        moveAndState, currentRemark = playerResult
        #print(who)
        #print(moveAndState)

        if moveAndState==None:
            FINISHED = True; continue
        move, currentState = moveAndState
        moveReport = "Move is by "+who+" to "+str(move)
        print(moveReport)
        utteranceReport = name +' says: '+currentRemark
        print(utteranceReport)
        if USE_HTML: gameToHTML.reportResult(moveReport)
        if USE_HTML: gameToHTML.reportResult(utteranceReport)
        possibleWin = winTesterForK(currentState, move, K)
        if possibleWin != "No win":
            FINISHED = True
            printState(currentState)
            if USE_HTML: gameToHTML.stateToHTML(currentState, finished=True)
            print(possibleWin)
            if USE_HTML: gameToHTML.reportResult(possibleWin)
            if USE_HTML: gameToHTML.endHTML()
            return
        printState(currentState)
        if USE_HTML: gameToHTML.stateToHTML(currentState)
        turnCount += 1
        #if turnCount == 9: FINISHED=True
    printState(currentState)
    if USE_HTML: gameToHTML.stateToHTML(currentState)
    who = currentState[1]
    print("Game over.")
    if USE_HTML: gameToHTML.reportResult("Game Over; it's a draw")
    if USE_HTML: gameToHTML.endHTML()
Пример #3
0
def runGame():
	currentState = INITIAL_STATE

	if USE_HTML:
		gameToHTML.startHTML(player1.nickname(), player2.nickname(), GAME_TYPE, 1)
	try:
		p1comment = player1.prepare(INITIAL_STATE, K, 'X', player2.nickname(), mode='Normal')
	except:
		report = 'Player 1 ('+player1.nickname()+' failed to prepare, and loses by default.'
		print(report)
		if USE_HTML: gameToHTML.reportResult(report)
		report = 'Congratulations to Player 2 ('+player2.nickname()+')!'
		print(report)
		if USE_HTML: gameToHTML.reportResult(report)
		if USE_HTML: gameToHTML.endHTML()
		return
	try:
		p2comment = player2.prepare(INITIAL_STATE, K, 'O', player1.nickname(), mode='Normal')
	except:
		report = 'Player 2 ('+player2.nickname()+' failed to prepare, and loses by default.'
		print(report)
		if USE_HTML: gameToHTML.reportResult(report)
		report = 'Congratulations to Player 1 ('+player1.nickname()+')!'
		print(report)
		if USE_HTML: gameToHTML.reportResult(report)
		if USE_HTML: gameToHTML.endHTML()
		return
		return

					
	print('The Gamemaster says, "Let\'s Play!"')
	print('The initial state is...')

	currentRemark = "The game is starting."
	if USE_HTML: gameToHTML.stateToHTML(currentState)

	XsTurn = True
	name = None
	global FINISHED
	FINISHED = False
	turnCount = 0
	printState(currentState)
	while not FINISHED:
		who = currentState[1]
		if XsTurn:
			playerResult = player1.makeMove(currentState, currentRemark, TIME_PER_MOVE)
			name = player1.nickname()
			XsTurn = False
		else:
			playerResult = player2.makeMove(currentState, currentRemark, TIME_PER_MOVE)
			name = player2.nickname()
			XsTurn = True
		moveAndState, currentRemark = playerResult
		if moveAndState==None:
			FINISHED = True; continue
		move, currentState = moveAndState
		moveReport = "Move is by "+who+" to "+str(move)
		print(moveReport)
		utteranceReport = name +' says: '+currentRemark
	#	print(utteranceReport)
	#	sleep(0.3)
		if USE_HTML: gameToHTML.reportResult(moveReport)
		if USE_HTML: gameToHTML.reportResult(utteranceReport)
		possibleWin = winTesterForK(currentState, move, K)
		if possibleWin != "No win":
			FINISHED = True
			printState(currentState)
			if USE_HTML: gameToHTML.stateToHTML(currentState, finished=True)
			print(possibleWin)
			if USE_HTML: gameToHTML.reportResult(possibleWin)
			if USE_HTML: gameToHTML.endHTML()
			return
		printState(currentState)
		if USE_HTML: gameToHTML.stateToHTML(currentState)
		turnCount += 1
		#if turnCount == 9: FINISHED=True
	printState(currentState)
	if USE_HTML: gameToHTML.stateToHTML(currentState)
	who = currentState[1]
	print("Game over.")
	if USE_HTML: gameToHTML.reportResult("Game Over; it's a draw")
	if USE_HTML: gameToHTML.endHTML()