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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
• Campbell Ritchie
• Tim Cooke
• Devaka Cooray
• Ron McLeod
• Jeanne Boyarsky
Sheriffs:
• Liutauras Vilda
• paul wheaton
• Junilu Lacar
Saloon Keepers:
• Tim Moores
• Stephan van Hulst
• Piet Souris
• Carey Brown
• Tim Holloway
Bartenders:
• Martijn Verburg
• Frits Walraven
• Himai Minh

# write the code to check for winner

Ranch Hand
Posts: 34
• Number of slices to send:
Optional 'thank-you' note:

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: 13082
67
• Number of slices to send:
Optional 'thank-you' note:
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
• Number of slices to send:
Optional 'thank-you' note:
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
• 1
• Number of slices to send:
Optional 'thank-you' note:
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
• Number of slices to send:
Optional 'thank-you' note:
This is probably the code they used behind the scenes in "War Games"!

WP

Andres John
Ranch Hand
Posts: 34
• Number of slices to send:
Optional 'thank-you' note:

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
• Number of slices to send:
Optional 'thank-you' note:

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

WP

Hmm... "WP" ... "WOPR" ... Coincidence?

 Don't play dumb with me! But you can try this tiny ad: the value of filler advertising in 2021 https://coderanch.com/t/730886/filler-advertising