• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

write the code to check for winner

 
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


i just want to know which method i should add for winner and explain me how this code work. i'm not asking you give me solution.
i know that to check for winner i need to use the matrix form which is w=[1 0 0 0 0], w=[0 1 0 0 0], w=[0 0 1 0 0], w=[0 0 0 1 0], w=[0 0 0 0 1], and so on
 
lowercase baba
Posts: 12871
62
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would be seriously amazed if anyone took the time to try and figure out your 450 lines of code that has exactly 8 comments.

Even if it were well commented, that is too much code to expect someone to go through.

finally, your question is too vague.

i just want to know which method i should add for winner and explain me how this code work.


questions like this can only be answered with:
First, figure out by hand what you need to do. How do you determine if someone is a winner? Then refine the steps and break it down into simple steps. Then, code that.
 
Bartender
Posts: 825
5
Python Ruby Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Wow, it's been a while since I've seen n-level nested loops (n -> Infinity) like these...

I would be seriously amazed if anyone took the time to try and figure out your 450 lines of code that has exactly 8 comments.


I would bet now that even OP won't be able to figure out how the code works in, like, 2 weeks...
 
Rancher
Posts: 2759
32
Eclipse IDE Spring Tomcat Server
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is this code? TicTacTOe? I am assuming that the function takes the token of the player ("X" or "O") and needs to check the board to see if "X" or "O" won.

One approach is to brute force it. There are 8 possible winning patterns in TicTacToe. Just check if the board matches one of those 8 patterns.

If you don;t want to brute force it, you should really keep a "score" for every row column and diagonal, and change the score everytime a move is made. So, let's say, an X mark does a +1 on ever row, col and diagonal that the cell belongs to, and O mark does a -1. You just check the scores for all the rows, columns and diagonals, if any of them is 3, X won.. if any of them is -3 O won. Bada Bing Bada Boom
 
Ranch Hand
Posts: 859
IBM DB2 Chrome Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is probably the code they used behind the scenes in "War Games"!

WP

 
Andres John
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Jayesh A Lalwani wrote:What is this code? TicTacTOe? I am assuming that the function takes the token of the player ("X" or "O") and needs to check the board to see if "X" or "O" won.

One approach is to brute force it. There are 8 possible winning patterns in TicTacToe. Just check if the board matches one of those 8 patterns.

If you don;t want to brute force it, you should really keep a "score" for every row column and diagonal, and change the score everytime a move is made. So, let's say, an X mark does a +1 on ever row, col and diagonal that the cell belongs to, and O mark does a -1. You just check the scores for all the rows, columns and diagonals, if any of them is 3, X won.. if any of them is -3 O won. Bada Bing Bada Boom



k now i'm getting the ideas thanks
 
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

William P O'Sullivan wrote:This is probably the code they used behind the scenes in "War Games"!

WP



Hmm... "WP" ... "WOPR" ... Coincidence?
 
    Bookmark Topic Watch Topic
  • New Topic