Beispiel #1
0
def main():
	print(GREET_STRING)
	gamestate = Gamestate()

	print("You are on page", gamestate.getCurrentPage())
	print("Your goal destination is", gamestate.getTarget(), "\n")
	while True:
		prompt = input('From here you can do the followning: \
			\n Type "where" to look at links you can click \
			\n Type "target" to see your target link again \
			\n Type "exit" to quit the game \
			\n Type "go" or "go "Title"" to follow a link \n \
			\nPlease Enter A Command: ')

		if prompt[0:2] == 'go':
			goToLink(prompt, gamestate)

		elif prompt == 'path':
			print(gamestate.getPath())

		elif prompt == 'target':
			print(gamestate.getTarget(), "\n")

		elif prompt == 'exit':
			quit()

		elif prompt == 'where':
			listAllLinks(gamestate)

		else:
			print('That was not a valid commmand, please try again \n')

		if gamestate.isWin():
			print('You win in ' + str(gamestate.getNumClicks()) + ' clicks')
			break;
Beispiel #2
0
# BLOKUS.PY
# Main file containing setup and gameplay loop

import sys
import numpy as np
import Pieces
import Players
import HumanPlayer
import MaxnPlayers
import MCTSPlayers
import Gamestate

# Initialize current gamestate variable
curr = Gamestate.Gamestate()
referenceHand = Gamestate.initHand()  # for checks, etc.

# Fill list of players with humans and AIs, based on player input
players = dict()
for i in range(1, 5):
    print("Is player %d AI or human?" % i)
    print("(0 for human, 1 for AI)")
    success = False

    while not success:
        try:
            n = int(raw_input())
            if n != 0 and n != 1 and n != 2 and n != 3 and n != 4 and n != 5 and n != 6:
                print("Please enter zero or one only")
            else:
                success = True
        except ValueError as e:
Beispiel #3
0
    def getMove(self, update):
        """Prompted with gamestate, return move chosen by MCTS with tree loaded from file."""

        # If this is the first time getMove is called, either read root from file
        # or initialize new one. Then set 'current' to last known gamestate
        if not hasattr(self, 'root'):
            if persistentMCPlayer.shouldReadTree:
                self.root = self.readTree()
            else:
                self.root = MCTree.MCNode(Gamestate.Gamestate())
            self.current = self.root

        # Determine which moves have been made by each player in order to
        # move 'current' down the tree to the node corresponding to update
        if not self.current.gamestate.equals(update):
            colorToCheck = self.color + 1
            if colorToCheck == 5:
                colorToCheck = 1
            while True:

                # Find move made by player, then move down tree to corresponding
                # node, or create it if necessary
                moveMade = self.findMoveMade(self.current.gamestate, update,
                                             colorToCheck)

                if moveMade in self.current.children:
                    self.current = self.current.children[moveMade]
                else:
                    new_gamestate = self.current.gamestate.duplicate()
                    new_gamestate.update(moveMade)
                    self.current.children[moveMade] = MCTree.MCNode(
                        new_gamestate, parent=self.current)
                    self.current = self.current.children[moveMade]

                # Go to next player in order
                colorToCheck = colorToCheck + 1
                if colorToCheck == 5:
                    colorToCheck = 1
                if colorToCheck == self.color:
                    break

        # Then repeat Monte Carlo iterations until you run out of time

        start_time = time.time()
        while (time.time() - start_time < 30):
            self.mcIteration()

        self.current.printTree()

        # And pick best move

        move = self.highestAvgPlayoutMove(self.current)

        # Update tree to reflect path taken
        if move in self.current.children:
            self.current = self.current.children[move]
        else:
            new_gamestate = self.current.duplicate()
            new_gamestate.update(move)
            self.current.children[move] = MCNode(new_gamestate,
                                                 parent=self.current)
            self.current = self.current.children[move]

        # Then return the move to make
        print("MAKING MOVE:")
        print(move)
        print("self.current.gamestate.board:")
        print(self.current.gamestate.board)
        return (move)
w = 320
h = 200
screen = pygame.display.set_mode((int(w * size_mult), int(h * size_mult)))
pygame.display.update()

images = {}
image_classes = ["misc_graphic", "cockpit", "fighter", "capship", "cutscene"]
for c in image_classes:
    for key, value in data_groups[c].items():
        images[key] = []
        for i in value.data.blocks:
            images[key].append([])
            for j in i.blocks:
                test_image = GameImage.GameImage(j)
                images[key][-1].append(test_image)

saves = {}
for key, value in data_groups["savegame"].items():
    saves[key] = []
    for i in value.data.blocks:
        saves[key].append(Gamestate.Gamestate(i))

test_image = images["recroom.vga"][0][0]

#test_image = GameImage.GameImage(data_groups["misc_graphic"]["briefing.vga"].data.blocks[7].blocks[3])
test_image.Draw(screen)
pygame.display.update()

while (1):
    if pygame.event.poll().type == pygame.KEYDOWN:
        break