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. Mongodb数据操作基础

    var mongodb = require('mongodb'); var server = new mongodb.Server('localhost', 27017, {auto_reconnec ...

  2. 【USACO】Milking Cows

    Three farmers rise at 5 am each morning and head for the barn to milk three cows. The first farmer b ...

  3. Hibernate —— ID的各种生成器(转)

    Hibernate中,<id>元素下的可选<generator>子元素是一个Java类的名字,用来为该持久化类的实例生成惟一标示,所有的生成器都实现net.sf.hiberna ...

  4. poj -1065 Wooden Sticks (贪心or dp)

    http://poj.org/problem?id=1065 题意比较简单,有n跟木棍,事先知道每根木棍的长度和宽度,这些木棍需要送去加工,第一根木棍需要一分钟的生产时间,如果当前木棍的长度跟宽度 都 ...

  5. 1343. Fairy Tale

    1343 想了好一会 以为会有什么定理呢 没想到 就试着搜了 看来素数还是很多的 跑的飞快 注意会有前导0的情况 还有0,1不是素数... #include <iostream> #inc ...

  6. tomcat下jndi的三种配置方式

    jndi(Java Naming and Directory Interface,Java命名和目录接口)是一组在Java应用中访问命名和目录服务的API.命名服务将名称和对象联系起来,使得我们可以用 ...

  7. ubuntu13.04云主机部署gitlab6.6

    GitLab 是何物? GitLab是 GitHub 的山寨版,GitLab几乎包含了GitHub的所有功能,还包含比较有特色的功能:Code Review,Wiki,Merge Requests,最 ...

  8. ASP.NET MVC路由配置

    一.命名参数规范+匿名对象 routes.MapRoute(name: "Default", url: "{controller}/{action}/{id}" ...

  9. 51nod1437 迈克步

    傻叉单调栈 #include<cstdio> #include<cstring> #include<cctype> #include<algorithm> ...

  10. 字符集设置为UTF-8

    vi /etc/my.cnf [mysqld] character-set-server=utf8 [mysql] default-character-set=utf8 来自为知笔记(Wiz)