From 0a04ed1c22dd8d955bcdec228b8c586225141a4f Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Thu, 28 Jul 2016 22:34:20 +0900 Subject: [PATCH] examples/2048: Refactoring --- examples/2048/2048/board.go | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/examples/2048/2048/board.go b/examples/2048/2048/board.go index 109ae3d2e..c30edd3fc 100644 --- a/examples/2048/2048/board.go +++ b/examples/2048/2048/board.go @@ -110,14 +110,16 @@ func (b *Board) Move(dir Dir) { if ni < 0 || ni >= b.size || nj < 0 || nj >= b.size { break } - tt := b.tileAt(ni, nj) + tt := tileAt(nextTiles, ni, nj) if tt == nil { ii = ni jj = nj continue } - nt := tileAt(nextTiles, ni, nj) - if t.value == tt.value && (nt == nil || !merged[nt]) { + if t.value != tt.value { + break + } + if !merged[tt] { ii = ni jj = nj }