当前位置: 首页 > 编程语言 > C#

使用四线(connect4)游戏实现和使用MinMax分享

时间:2023-04-10 12:27:55 C#

使用四线(connect4)游戏实现和使用MinMax游戏。我想我明白了,它应该构建一个可能的板树到一定深度,评估它们并返回它们的分数,然后我们只取这些分数的最大值。因此,aiChooseCol()通过调用MinMax()aiChooseCol()检查每个可能列的得分,并返回得分最高的列。现在我不确定,这是调用MinMax()的正确方法吗?检查temp=Math.Max(temp,1000);是否正确temp=Math.Max(temp,1000);?我仍然没有启发式,但这至少应该确定一个获胜列并选择它,但目前它只是选择左边的第一个空闲列......我不知道我做错了什么。privateintAiChooseCol(){intbest=-1000;intcol=0;for(inti=0;ibest){best=t;科尔=我;}m_Board.RemoveTopCoinFromCol(i);}}返回列;}privateintMinMax(intDepth,boardBoard,charPlayerSign){inttemp=0;if(Depth<=0){//从启发式函数返回returntemp;}charotherPlayerSign=board.GetOtherPlayerSign(PlayerSign);charcheckBoard=Board.CheckBoardForWin();如果(checkBoard==PlayerSign){返回1000;}elseif(checkBoard==otherPlayerSign){return-1000;}elseif(!Board.CheckIfBoardIsNotFull()){返回0;//tie}if(PlayerSign==m_Sign)//最大化Playerismyself{temp=-1000;for(inti=0;i();for(inti=0;it.Item2);varbestMoves=moves.Where(t=>t.Item2==maxMoveScore).ToList();board.DropCoin(2,bestMoves[random.Next(0,bestMoves.Count)].Item1);Console.WriteLine(板);if(board.Winner==2){控制台。WriteLine("你输了!");休息;}if(board.IsFull){控制台e.WriteLine("领带!");休息;}}Console.WriteLine("DONE");控制台.ReadKey();}privatestaticintMinMax(intdepth,Boardboard,boolmaximizingPlayer){if(depth=0;for(intk=1;k本文收集自网络,不代表立场,如涉及侵权,请点击右边联系管理员删除,如有转载请注明出处: