GithubHelp home page GithubHelp logo

2048-ai's People

Contributors

dvrkps avatar xwjdsh avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

2048-ai's Issues

docker is error

docker build -t 2048-ai .
Sending build context to Docker daemon 1.698 MB
Step 1/12 : FROM golang:1.9 as builder
Error parsing reference: "golang:1.9 as builder" is not a valid repository/tag: invalid reference format

My golang version is go version go1.9.2 linux/amd64
OS is Ubuntu 16.04

it get NONE direction

image

// 这种情况会返回None结果,其实也差不多快要结束了。
AI.go

func (a *AI) Search() grid.Direction {
	var (
		bestDire  = grid.NONE
		bestScore float64
	)
	// depth value depending on grid's max value.
	dept := a.deptSelect()
	for _, dire := range directions {
		newGrid := a.Grid.Clone()
		if newGrid.Move(dire) {.     **//It No Caculate  score generated by Move.**
			// Could move.
			// Active is false represent computer should fill number to grid now.

			newAI := &AI{Grid: newGrid, Active: false}
			if newScore := newAI.expectSearch(dept); newScore > bestScore {
				bestDire = dire
				bestScore = newScore
			}
		}
	}
	return bestDire
}
  1. 在第一次遍历方向时并没有计算移动的分数,会不会有影响?
  2. 如果所有方向分数都为0时,这个时候差不多要结束游戏,但返回的结果为grid.NONE,如果返回一个可以移动的反向是不是更好?
func (g *Grid) Move(d Direction) (bool, float64) {
	originData := g.Data
	data := &g.Data
	Score := float64(0)
	switch d {
	case UP:
		for y := 0; y < 4; y++ {
			for x := 0; x < 3; x++ {
				for nx := x + 1; nx <= 3; nx++ {
					if data[nx][y] > 0 {
						if data[x][y] <= 0 {
							data[x][y] = data[nx][y]
							data[nx][y] = 0
							x -= 1
						} else if data[x][y] == data[nx][y] {
							data[x][y] += data[nx][y]
							data[nx][y] = 0
							Score += float64(data[x][y] * 2)
						}
						break
					}
				}
			}
		}
	case DOWN:
		for y := 0; y < 4; y++ {
			for x := 3; x > 0; x-- {
				for nx := x - 1; nx >= 0; nx-- {
					if data[nx][y] > 0 {
						if data[x][y] <= 0 {
							data[x][y] = data[nx][y]
							data[nx][y] = 0
							x += 1
						} else if data[x][y] == data[nx][y] {
							data[x][y] += data[nx][y]
							data[nx][y] = 0
							Score += float64(data[x][y] * 2)
						}
						break
					}
				}
			}
		}
	case LEFT:
		for x := 0; x < 4; x++ {
			for y := 0; y < 3; y++ {
				for ny := y + 1; ny <= 3; ny++ {
					if data[x][ny] > 0 {
						if data[x][y] <= 0 {
							data[x][y] = data[x][ny]
							data[x][ny] = 0
							y -= 1
						} else if data[x][y] == data[x][ny] {
							data[x][y] += data[x][ny]
							data[x][ny] = 0
							Score += float64(data[x][y] * 2)
						}
						break
					}
				}
			}
		}
	case RIGHT:
		for x := 0; x < 4; x++ {
			for y := 3; y > 0; y-- {
				for ny := y - 1; ny >= 0; ny-- {
					if data[x][ny] > 0 {
						if data[x][y] <= 0 {
							data[x][y] = data[x][ny]
							data[x][ny] = 0
							y += 1
						} else if data[x][y] == data[x][ny] {
							data[x][y] += data[x][ny]
							data[x][ny] = 0
							Score += float64(data[x][y] * 2)
						}
						break
					}
				}
			}
		}
	}
	return utils.Diff(*data, originData), Score
}

 //优化后的Search函数
func (a *AI) Search() grid.Direction {
	var (
		bestDire  = grid.NONE
		bestScore float64
	)
	// depth value depending on grid's max value.
	// 根据场上最大分数来判断搜索深度
dept := a.deptSelect()
	for _, dire := range directions {
		newGrid := a.Grid.Clone()
       
		canmove, score := newGrid.Move(dire)
		if canmove {
               if bestDire == grid.NONE {
				bestDire = dire
			}
			// Could move.
			// Active is false represent computer should fill number to grid now.
			newAI := &AI{Grid: newGrid, Active: false}
			if newScore := newAI.expectSearch(dept); newScore+score > bestScore {
				bestDire = dire
				bestScore = newScore
			}

		}
	}

	return bestDire

start container failed,iptables: No chain/target/match by that name

[root@host ~]# docker run -p 8080:8080 wendellsun/2048-ai
Unable to find image 'wendellsun/2048-ai:latest' locally
latest: Pulling from wendellsun/2048-ai
a52c7d714e5f: Pull complete
15e0dc04655d: Pull complete
f2435a32f659: Pull complete
bdf9109f7f82: Pull complete
9d85d078285a: Pull complete
9cc6c519d7ab: Pull complete
7537db3001ad: Pull complete
0a11135497c2: Pull complete
8678b49e634e: Pull complete
Digest: sha256:82bff73de628bf2fd14f345636937e374e3afdf0f8773dec38776df50fd7b1e2
Status: Downloaded newer image for wendellsun/2048-ai:latest
Error response from daemon: Cannot start container c26c446a7e8ce4a970e976fd0f2c7ca4e165a4534af350d143a0a5603caa116e: iptables failed: iptables -t nat -A DOCKER -p tcp -d 0/0 --dport 8080 -j DNAT --to-destination 192.168.42.2:8080 ! -i docker0: iptables: No chain/target/match by that name.
 (exit status 1)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.