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. hibernate配置之<property name="hbm2ddl.auto">create</property>导致每次创建SessionFactory都清空数据库中的数据

    参考:http://stackoverflow.com/questions/6611437/how-to-make-hibernate-not-drop-tables 我遇到的问题就是: List l ...

  2. 【算法题】- 求和等于K子数组

    一整数(有正有负)数组,用尽量少的时间计算数组中和为某个整数的所有子数组 public class SumK { public static void main(String[] args) { in ...

  3. Data Base sqlServer sa用户登陆失败的解决办法

    sqlserver sa用户登陆失败的解决办法 如下图以此模仿: 1.右键-属性 2.找到安全: 3.勾选如图: 4.sa用户密码重置: 5.服务重启:

  4. 《Linux内核设计与实现》读书笔记(十一)- 定时器和时间管理【转】

    转自:http://www.cnblogs.com/wang_yb/archive/2013/05/10/3070373.html 系统中有很多与时间相关的程序(比如定期执行的任务,某一时间执行的任务 ...

  5. linux c 生成uuid

    /********方法一**********/#include <stdio.h> #include <stdlib.h> #include <string.h> ...

  6. poj - 3259 Wormholes (bellman-ford算法求最短路)

    http://poj.org/problem?id=3259 农夫john发现了一些虫洞,虫洞是一种在你到达虫洞之前把你送回目的地的一种方式,FJ的每个农场,由n块土地(编号为1-n),M 条路,和W ...

  7. 第三方登录(2)Android客户瑞上第三方登录百度教程

    1,在 http://developer.baidu.com/  注册成开发者 不注册看不到开发相关的链接地址.点自己的用户名,在弹出菜单显示有 <用户中心> ,没有就是没注册. 2,找到 ...

  8. 用root直接登入ubuntu 14_04

    官网下载地址:http://www.ubuntu.com/download/desktop64位桌面版:http://www.ubuntu.com/ubuntu-releases/14.04/ubun ...

  9. BZOJ 2956 模积和

    题目链接:http://61.187.179.132/JudgeOnline/problem.php?id=2956 题意:给出n和m.计算: 思路: i64 n,m; i64 cal(i64 m,i ...

  10. UVa 1626 (输出方案) Brackets sequence

    正规括号序列定义为: 空序列是正规括号序列 如果S是正规括号序列,那么[S]和(S)也是正规括号序列 如果A和B都是正规括号序列,则AB也是正规括号序列 输入一个括号序列,添加尽量少的括号使之成为正规 ...