N*N matrix is given with input red or black.You can move horizontally, vertically or diagonally. If 3 consecutive samecolor found, that color will get 1 point. So if 4 red are vertically then pointis 2. Find the winner.

def tic_tac_toe(board,n)
red, black =0, 0
n.times do |i|
n.times do |j|
if board[i][j]
red += 1 if i<m-2 and board[i+1][j] and board[i+2][j]
red += 1 if j<n-2 and board[i][j+1] and board[i][j+2]
red += 1 if i<m-2 and j<n-2 and board[i+1][j+1] and board[i+2][j+2]
red += 1 if i>=2 and j>=2 and board[i-1][j-1] and board[i-2][j-2]
else
black += 1 if i<m-2 and !board[i+1][j] and !board[i+2][j]
black += 1 if j<n-2 and !board[i][j+1] and !board[i][j+2]
black += 1 if i<m-2 and j<n-2 and !board[i+1][j+1] and !board[i+2][j+2]
black += 1 if i>=2 and j>=2 and !board[i-1][j-1] and !board[i-2][j-2]
end
end
end
red > black
end

Epic - Tic Tac Toe的更多相关文章

  1. Principle of Computing (Python)学习笔记(7) DFS Search + Tic Tac Toe use MiniMax Stratedy

    1. Trees Tree is a recursive structure. 1.1 math nodes https://class.coursera.org/principlescomputin ...

  2. POJ 2361 Tic Tac Toe

    题目:给定一个3*3的矩阵,是一个井字过三关游戏.开始为X先走,问你这个是不是一个合法的游戏.也就是,现在这种情况,能不能出现.如果有人赢了,那应该立即停止.那么可以知道X的步数和O的步数应该满足x= ...

  3. 【leetcode】1275. Find Winner on a Tic Tac Toe Game

    题目如下: Tic-tac-toe is played by two players A and B on a 3 x 3 grid. Here are the rules of Tic-Tac-To ...

  4. 2019 GDUT Rating Contest III : Problem C. Team Tic Tac Toe

    题面: C. Team Tic Tac Toe Input file: standard input Output file: standard output Time limit: 1 second M ...

  5. [CareerCup] 17.2 Tic Tac Toe 井字棋游戏

    17.2 Design an algorithm to figure out if someone has won a game oftic-tac-toe. 这道题让我们判断玩家是否能赢井字棋游戏, ...

  6. python 井字棋(Tic Tac Toe)

    说明 用python实现了井字棋,整个框架是本人自己构思的,自认为比较满意.另外,90%+的代码也是本人逐字逐句敲的. minimax算法还没完全理解,所以参考了这里的代码,并作了修改. 特点 可以选 ...

  7. ACM-Team Tic Tac Toe

    我的代码: #include <bits/stdc++.h> using namespace std; int main() { char a[3][3]; int i,j=0; for( ...

  8. LeetCode 5275. 找出井字棋的获胜者 Find Winner on a Tic Tac Toe Game

    地址 https://www.acwing.com/solution/LeetCode/content/6670/ 题目描述A 和 B 在一个 3 x 3 的网格上玩井字棋. 井字棋游戏的规则如下: ...

  9. 【Python五篇慢慢弹】数据结构看python

    数据结构看python 作者:白宁超 2016年10月9日14:04:47 摘要:继<快速上手学python>一文之后,笔者又将python官方文档认真学习下.官方给出的pythondoc ...

随机推荐

  1. ubuntu启动eclipse时出错cannot open display

    由于要学习hadoop,就在ubuntu下创建了一个hadoop用户,但是eclipse是在naomi用户下装的,在root和naomi用户下都能正常启动,但是一旦切换到hadoop用户,试着启动ec ...

  2. ubuntu下安装与测试mysql

    1.在决定安装mysql之前,要先确定系统是否已经安装mysql. 输入: 1 mysql 结果:说明尚未安装mysql The program 'mysql' is currently notins ...

  3. 自适应高度的 textarea

    <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <m ...

  4. iMpACT中的Xilinx Prom烧录

    2014-01-06 19:56:37 在http://bbs.21ic.com/icview-361925-1-1.html中有比较详细的介绍. 下面的转自:http://xilinx.eetren ...

  5. MongoDB操作(.net)

    一.查询 var doc = new Document(); 1.模糊查询var reg = new MongoRegex(".*" + qry.名称 + ".*&quo ...

  6. HUD-1142

    A Walk Through the Forest Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Jav ...

  7. Vim 新用法

    daw , delete a word cw , delete from cursor to the end then insert mode a word 移动: f ; Aa Oo Cc Ii S ...

  8. 9.cadence.封装1[原创]

    一.封装中几个重要的概念 软件如下: ①.Regular pad(正规焊盘) 用在:top layer,bottom layer,internal layer(信号层) ②.thermal relie ...

  9. C#图片切割、图片压缩、缩略图生成

    C#图片切割.图片压缩.缩略图生成的实现代码 /// 图片切割函数  /// </summary>  /// <param name="sourceFile"&g ...

  10. Android启动过程以及各个镜像的关系

    Android启动过程 Android在启动的时候,会由UBOOT传入一个init参数,这个init参数指定了开机的时候第一个运行的程序,默认就是init程序,这个程序在ramdisk.img中.可以 ...