当前位置: 首页>>代码示例>>Golang>>正文


Golang Entity.CreateTarget方法代码示例

本文整理汇总了Golang中github.com/twoodhouse/coup-sim/model/log.Entity.CreateTarget方法的典型用法代码示例。如果您正苦于以下问题:Golang Entity.CreateTarget方法的具体用法?Golang Entity.CreateTarget怎么用?Golang Entity.CreateTarget使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在github.com/twoodhouse/coup-sim/model/log.Entity的用法示例。


在下文中一共展示了Entity.CreateTarget方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: DoTurn

//order of turn operation:
//1. Assign action and target
//2. Check general challenge concerning action
//3. Check block from targeted player
//4. Check challenge concerning block from source player
//5. Set action results given challenge/block success
func DoTurn(player *player.Entity, otherPlayers []*player.Entity, log *log.Entity, table *table.Entity, turnCounter int) (*log.Entity, *table.Entity) {
	log.SetPlayerName(player.Name())
	action := player.Strategy().GetAction(log, table.PlayerNames(), table.PlayerCoins(), table.FaceupDecks(), player.Deck())
	targetedPlayer := player //set default - not used unless assassinate or steal happens
	log.SetActionName(action)
	challengeLoss := false
	var target string

	//mid-game coin outputs
	// fmt.Print(player.Name() + ": ")
	// fmt.Print(player.Coins())
	// fmt.Println()

	if !player.Dead() && action != "tax" && action != "income" && action != "foreign_aid" && action != "coup" && action != "steal" && action != "assassinate" && action != "exchange" && action != "coup" {
		disqualifyPlayer(player, table, log, "Player attempted invalid action "+action)
	}

	if action != "coup" && player.Coins() >= 10 && !player.Dead() {
		disqualifyPlayer(player, table, log, "Player had 10+ coins and did not coup")
	}

	if action == "coup" && player.Coins() < 7 && !player.Dead() {
		disqualifyPlayer(player, table, log, "Player had "+strconv.Itoa(player.Coins())+" coins and needed 7 to Coup")
	}

	if action == "assassinate" && !player.Dead() {
		if player.Coins() < 3 {
			disqualifyPlayer(player, table, log, "Player had "+strconv.Itoa(player.Coins())+" coins and needed 3 to Assassinate")
		} else {
			player.AddCoins(-3)
		}
	}

	//get target for certain actions
	if action == "steal" || action == "assassinate" || action == "coup" && !player.Dead() {
		target = player.Strategy().GetTarget(log, table.PlayerNames(), table.PlayerCoins(), table.FaceupDecks(), player.Deck())
		if validLiveOtherPlayerName(otherPlayers, target) {
			targetedPlayer = playerByName(otherPlayers, target)
			log.CreateTarget(target)
		} else {
			disqualifyPlayer(player, table, log, "Target '"+target+"' is not a valid opposing-player name")
		}
	}

	//top-level challenge logic - it can only happen with these actions
	if (action == "tax" || action == "steal" || action == "assassinate" || action == "exchange") && !player.Dead() {
		for i := 0; i < len(otherPlayers); i++ {
			if !otherPlayers[i].Dead() && otherPlayers[i].Strategy().GetChallenge(log, table.PlayerNames(), table.PlayerCoins(), table.FaceupDecks(), otherPlayers[i].Deck()) {
				challengeSuccess := !player.Deck().HasCardForAction(action)
				losingPlayer := player
				if challengeSuccess {
					challengeLoss = true
					losingPlayer = player
				} else {
					losingPlayer = otherPlayers[i]
					var cardValue int
					switch action {
					case "tax":
						cardValue = 1
					case "steal":
						cardValue = 2
					case "assassinate":
						cardValue = 3
					case "block":
						cardValue = 4
					case "exchange":
						cardValue = 5
					}
					swapChallengedCard(player, table, log, cardValue)
				}
				log.CreateChallenge(otherPlayers[i].Name(), challengeSuccess)
				cardLoss := revealCard(losingPlayer, table, log)
				log.CreateChallengeCardLoss(cardLoss)
				break
			}
		}
	}

	if (action == "steal" || action == "assassinate") && !player.Dead() && !challengeLoss && !targetedPlayer.Dead() {
		if targetedPlayer.Strategy().GetBlock(log, table.PlayerNames(), table.PlayerCoins(), table.FaceupDecks(), targetedPlayer.Deck()) {
			log.CreateBlock()
			var blockCardClaim int
			if action == "steal" {
				blockCardClaim = targetedPlayer.Strategy().GetStealBlockCardChoice(log, table.PlayerNames(), table.PlayerCoins(), table.FaceupDecks(), targetedPlayer.Deck())
				log.CreateBlockCardClaim(blockCardClaim)
				if blockCardClaim != 2 && blockCardClaim != 5 {
					disqualifyPlayer(targetedPlayer, table, log, "Block card '"+strconv.Itoa(blockCardClaim)+"' is not valid for blocking steal'")
				}
			}
			if player.Strategy().GetChallenge(log, table.PlayerNames(), table.PlayerCoins(), table.FaceupDecks(), player.Deck()) {
				var neededCardAction string
				if action == "steal" {
					if blockCardClaim == 2 {
						neededCardAction = "steal"
//.........这里部分代码省略.........
开发者ID:twoodhouse,项目名称:coup-sim,代码行数:101,代码来源:controller.go


注:本文中的github.com/twoodhouse/coup-sim/model/log.Entity.CreateTarget方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。