220 - Othello

All about problems in Volume 2. If there is a thread about your problem, please use it. If not, create one with its number in the subject.

Moderator: Board moderators

Post Reply
Robert
New poster
Posts: 2
Joined: Sun Jul 04, 2004 2:39 pm
Location: Germany

220 WA Problem

Post by Robert » Fri Jul 09, 2004 7:49 pm

Hej,

I got a WA problem with my program. Can someone, whose program was accepted, run this program with the following input and post the output?

Thanks

P.S. My Output for the Input is at the end...

my INPUT Start
6
WWWWB---
WWWB----
WWB-----
WB------
--------
--------
--------
--------
B
L
M43
L
M25
L
Q
--------
--------
--------
---WB---
---BW---
--------
--------
--------
W
L
M35
L
Q
WWWWB---
WWWB----
WWB-----
WB------
--------
--------
--------
--------
B
L
M25
L
Q
WWWWB---
WWWBW---
WWBW----
WBW-----
-BW-----
---B----
--------
--------
B
L
M25
L
Q
--------
--------
--------
---WB---
---BW---
--------
--------
--------
B
L
M43
L
M35
L
M26
L
M33
L
M65
L
M17
L
M22
L
M75
L
M76
L
M42
L
M85
L
M63
L
M25
L
M56
L
M66
L
M74
L
M64
L
M34
L
M53
L
M36
L
M84
L
M83
L
M73
L
M86
L
M27
L
M11
L
M62
L
M16
L
M41
L
M82
L
M15
L
M37
L
M18
L
M32
L
M31
L
M51
L
M52
L
M23
L
M14
L
M12
L
M13
L
M21
L
M47
L
M46
L
M72
L
M48
L
M57
L
M38
L
M28
L
M58
L
M68
L
M61
L
M24
L
M67
L
M78
L
M77
L
M87
L
M88
L
M81
L
M71
L
Q
--------
--------
--------
---WB---
---BW---
--------
--------
--------
W
L
M35
L
Q
my INPUT End


my OUTPUT Start
No legal move.
Black - 2 White - 13
(5,1)
Black - 1 White - 15
(3,5) (5,1)
WWWWB---
WWWWW---
WWW-----
WWW-----
--------
--------
--------
--------

(3,5) (4,6) (5,3) (6,4)
Black - 1 White - 4
(3,4) (3,6) (5,6)
--------
--------
----W---
---WW---
---BW---
--------
--------
--------

No legal move.
Black - 3 White - 12
(3,5)
WWWWB---
WWWWW---
WWB-----
WB------
--------
--------
--------
--------

(1,6) (2,6) (3,5) (4,4) (5,4) (6,3)
Black - 5 White - 15
(1,6) (3,5) (4,4) (5,4) (6,3)
WWWWB---
WWWWW---
WWBW----
WBW-----
-BW-----
---B----
--------
--------

(3,4) (4,3) (5,6) (6,5)
Black - 4 White - 1
(3,3) (3,5) (5,3)
Black - 3 White - 3
(2,6) (3,6) (4,6) (5,6) (6,6)
Black - 5 White - 2
(2,5) (3,3) (4,2) (5,3) (6,3)
Black - 4 White - 4
(2,3) (3,4) (3,6) (4,6) (5,3) (5,6) (6,5)
Black - 7 White - 2
(1,7) (4,2) (4,6) (5,3) (6,4) (6,6)
Black - 5 White - 5
(2,2) (2,3) (2,5) (3,4)
Black - 8 White - 3
(5,3) (7,5)
Black - 5 White - 7
(3,6) (4,6) (5,6) (6,6) (7,6)
Black - 7 White - 6
(1,1) (4,2) (5,3) (6,3) (7,7)
Black - 5 White - 9
(2,5) (3,2) (3,4) (3,6) (5,1) (5,3) (5,6) (6,6) (7,4) (8,5)
Black - 7 White - 8
(1,1) (2,3) (2,4) (5,3) (6,3) (6,4) (8,7)
Black - 6 White - 10
(2,5) (3,2) (5,1) (5,3) (6,6)
Black - 10 White - 7
(1,1) (2,3) (2,4) (3,6) (4,6) (5,6) (6,6) (8,7)
Black - 9 White - 9
(2,7) (3,2) (4,1) (4,7) (5,1) (5,3) (6,6) (6,7) (7,2)
Black - 12 White - 7
(2,3) (2,4) (3,4) (3,6) (4,6) (5,3) (7,4) (8,6) (8,7)
Black - 11 White - 9
(2,7) (3,2) (4,1) (4,6) (5,1) (5,2) (5,3) (5,7) (6,4) (6,7) (7,2) (7,3)
Black - 14 White - 7
(2,3) (2,4) (3,4) (3,6) (4,6) (5,3) (6,7) (7,7) (8,6) (8,7)
Black - 10 White - 12
(2,7) (3,2) (4,6) (4,7) (5,1) (5,2) (5,3) (5,7) (6,2) (7,3) (8,3)
Black - 15 White - 8
(1,5) (1,6) (2,3) (2,4) (3,2) (3,6) (5,2) (6,2) (6,7) (7,7) (8,6)
Black - 14 White - 10
(2,4) (2,7) (3,1) (3,7) (4,1) (4,6) (4,7) (5,1) (5,2) (5,7) (6,2) (7,2) (7,3) (8,3) (8,4)
Black - 16 White - 9
(1,4) (1,5) (1,6) (2,3) (2,4) (3,2) (5,2) (6,2) (6,7) (8,3) (8,6)
Black - 14 White - 12
(2,4) (2,7) (3,1) (3,7) (4,1) (4,6) (4,7) (5,1) (5,2) (5,7) (6,2) (7,2) (7,3) (8,2)
Black - 17 White - 10
(1,4) (1,5) (1,6) (2,3) (2,4) (3,2) (5,2) (6,2) (6,7) (7,2) (8,6) (8,7)
Black - 10 White - 18
(2,4) (2,7) (3,7) (4,1) (4,6) (4,7) (5,1) (5,2) (5,7) (6,2) (6,7) (7,7) (8,7)
Black - 14 White - 15
(1,1) (1,5) (1,6) (2,3) (2,4) (3,2) (3,7) (4,6) (5,2) (6,2) (7,2) (8,2)
Black - 10 White - 20
(2,3) (2,4) (3,2) (4,1) (4,6) (4,7) (5,2) (5,7) (6,2) (6,7) (7,7) (8,7)
Black - 14 White - 17
(1,5) (1,6) (3,2) (3,7) (4,6) (5,1) (5,2) (6,1) (7,1) (7,2) (8,2)
Black - 13 White - 19
(1,4) (1,5) (2,3) (2,4) (3,1) (3,2) (4,1) (4,6) (4,7) (5,7) (6,7) (7,7) (8,7)
Black - 15 White - 18
(2,8) (3,1) (3,2) (3,7) (3,8) (4,6) (4,7) (5,1) (5,2) (6,1) (7,1) (7,2) (8,2)
Black - 14 White - 20
(1,4) (1,5) (2,3) (2,4) (3,2) (4,7) (5,7) (6,7) (7,2) (7,7) (8,7)
Black - 16 White - 19
(1,4) (3,1) (3,2) (3,7) (3,8) (4,6) (5,1) (5,2) (6,1) (7,1)
Black - 13 White - 23
(1,8) (2,3) (2,4) (2,8) (4,6) (4,7) (4,8) (5,7) (6,7) (7,2) (7,7) (8,7)
Black - 18 White - 19
(3,1) (3,2) (5,1) (5,2) (6,1) (7,1)
Black - 16 White - 22
(1,2) (2,3) (2,4) (3,1) (3,8) (4,7) (4,8) (5,2) (5,7) (6,7) (7,2) (7,7)
Black - 21 White - 18
(2,1) (2,3) (2,4) (4,6) (5,1) (5,2) (6,1) (7,2)
Black - 20 White - 20
(1,2) (1,3) (3,8) (4,7) (4,8) (5,2) (5,7) (6,1) (6,7) (7,1) (7,2) (7,7) (8,7)
Black - 22 White - 19
(2,1) (2,3) (2,4) (7,2)
Black - 16 White - 26
(1,2) (1,3) (1,4) (2,4) (3,8) (4,6) (4,7) (4,8) (5,7) (6,1) (7,1) (7,2) (7,7) (8,7)
Black - 18 White - 25
(1,2) (1,3) (2,1) (2,4) (6,1)
Black - 17 White - 27
(1,3) (2,4) (3,8) (4,6) (4,7) (4,8) (5,7) (6,1) (7,1) (7,2) (7,7) (8,7)
Black - 19 White - 26
(2,1) (6,1)
Black - 15 White - 31
(2,4) (3,8) (4,6) (4,7) (4,8) (5,7) (7,1) (7,2) (7,7)
Black - 19 White - 28
(3,8) (4,6) (5,7) (6,1) (6,7)
Black - 18 White - 30
(2,4) (5,7) (6,1) (6,7) (7,1) (7,2) (7,7) (8,7)
Black - 24 White - 25
(2,4) (2,8) (3,8) (4,8) (6,1) (7,1)
Black - 23 White - 27
(2,4) (3,8) (5,7) (5,8) (6,7) (7,7) (8,7)
Black - 28 White - 23
(2,8) (3,8) (5,8) (6,1) (6,7) (7,1)
Black - 21 White - 31
(2,4) (2,8) (5,8) (6,7) (7,7) (8,7)
Black - 23 White - 30
(5,8) (6,1) (6,7) (6,8) (7,1) (8,1)
Black - 22 White - 32
(2,4) (6,7) (6,8) (7,7) (8,7)
Black - 27 White - 28
(6,1) (6,7) (7,1) (8,1)
Black - 23 White - 33
(2,4) (6,7) (7,1) (7,7) (8,1) (8,7)
Black - 27 White - 30
(6,7)
Black - 26 White - 32
(7,1) (7,7) (7,8) (8,1) (8,7)
Black - 29 White - 30
(7,7)
Black - 28 White - 32
(7,1) (8,1) (8,7) (8,8)
Black - 35 White - 26
(8,8)
Black - 33 White - 29
(7,1) (8,1)
Black - 36 White - 27
(7,1)
Black - 34 White - 30
No legal move.
WWBBBBBB
WWWBBBBB
WWBBBWBB
WBWBBBBB
WWWBBBBB
WWBWBWBB
WWWWWBWB
BWWWWWWW

(3,5) (4,6) (5,3) (6,4)
Black - 1 White - 4
(3,4) (3,6) (5,6)
--------
--------
----W---
---WW---
---BW---
--------
--------
--------
my Output End

User avatar
GreenPenInc
Learning poster
Posts: 53
Joined: Sat May 01, 2004 9:31 pm
Contact:

Post by GreenPenInc » Fri Aug 27, 2004 3:47 pm

Hi Robert,

I get the same output as you with one discrepancy. When it shows the number for black and for white, you leave a space and then print the integer, whereas I leave a space and print the integer right-justified in a field of width 2. To show what I mean, here's an excerpt from the diff I ran on our outputs.

Code: Select all

*snipped*
> Black - 12 White - 7
82c82
< Black - 11 White -  9
---
> Black - 11 White - 9
84c84
< Black - 14 White -  7
---
> Black - 14 White - 7
88c88
< Black - 15 White -  8
---
> Black - 15 White - 8
92c92
< Black - 16 White -  9
---
> Black - 16 White - 9
182c182
< Black -  1 White -  4
---
> Black - 1 White - 4
Try fixing that up, maybe it'll help.
_-(GPI)-_

"Finally I have freed myself from the clutches of the garbage fairy!"

sclo
Guru
Posts: 519
Joined: Mon Jan 23, 2006 10:45 pm
Location: Vancouver, BC, Canada
Contact:

Post by sclo » Tue Mar 14, 2006 11:10 pm

My advice is to try to recode it until it is less than 80 lines. It too easy to make mistakes in long code.

User avatar
gradientcurl
New poster
Posts: 16
Joined: Mon Jun 26, 2006 9:33 am
Contact:

something abt the input

Post by gradientcurl » Tue Dec 19, 2006 12:54 pm

ref to test case 4

Code: Select all

WWWWB---
WWWBW---
WWBW----
WBW-----
-BW-----
---B----
--------
--------
B
L
M25
L
Q
(2,5) is already occupied. i suppose the program will not receive such an input?? (maybe (2,5) should be '-' instead)

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 220 WA Problem

Post by brianfry713 » Sat Oct 15, 2011 2:45 am

Here's the input from above:

Code: Select all

6
WWWWB---
WWWB----
WWB-----
WB------
--------
--------
--------
--------
B
L
M43
L
M25
L
Q
--------
--------
--------
---WB---
---BW---
--------
--------
--------
W
L
M35
L
Q
WWWWB---
WWWB----
WWB-----
WB------
--------
--------
--------
--------
B
L
M25
L
Q
WWWWB---
WWWBW---
WWBW----
WBW-----
-BW-----
---B----
--------
--------
B
L
M25
L
Q
--------
--------
--------
---WB---
---BW---
--------
--------
--------
B
L
M43
L
M35
L
M26
L
M33
L
M65
L
M17
L
M22
L
M75
L
M76
L
M42
L
M85
L
M63
L
M25
L
M56
L
M66
L
M74
L
M64
L
M34
L
M53
L
M36
L
M84
L
M83
L
M73
L
M86
L
M27
L
M11
L
M62
L
M16
L
M41
L
M82
L
M15
L
M37
L
M18
L
M32
L
M31
L
M51
L
M52
L
M23
L
M14
L
M12
L
M13
L
M21
L
M47
L
M46
L
M72
L
M48
L
M57
L
M38
L
M28
L
M58
L
M68
L
M61
L
M24
L
M67
L
M78
L
M77
L
M87
L
M88
L
M81
L
M71
L
Q
--------
--------
--------
---WB---
---BW---
--------
--------
--------
W
L
M35
L
Q
Output from my AC program:

Code: Select all

No legal move.
Black -  2 White - 13
(5,1)
Black -  3 White - 13
(1,6) (2,6) (3,4) (3,5) (3,6)
WWWWB---
WWWBB---
WWW-----
WWW-----
--------
--------
--------
--------

(3,5) (4,6) (5,3) (6,4)
Black -  1 White -  4
(3,4) (3,6) (5,6)
--------
--------
----W---
---WW---
---BW---
--------
--------
--------

No legal move.
Black -  3 White - 12
(3,5)
WWWWB---
WWWWW---
WWB-----
WB------
--------
--------
--------
--------

(1,6) (2,6) (3,5) (4,4) (5,4) (6,3)
Black -  9 White - 11
(1,6) (2,6) (3,5) (3,6) (4,4) (4,5) (5,1) (5,4) (6,2) (6,3) (7,5)
WWWWB---
WWWBB---
WWBB----
WBB-----
-BW-----
---B----
--------
--------

(3,4) (4,3) (5,6) (6,5)
Black -  4 White -  1
(3,3) (3,5) (5,3)
Black -  3 White -  3
(2,6) (3,6) (4,6) (5,6) (6,6)
Black -  5 White -  2
(2,5) (3,3) (4,2) (5,3) (6,3)
Black -  4 White -  4
(2,3) (3,4) (3,6) (4,6) (5,3) (5,6) (6,5)
Black -  7 White -  2
(1,7) (4,2) (4,6) (5,3) (6,4) (6,6)
Black -  5 White -  5
(2,2) (2,3) (2,5) (3,4)
Black -  8 White -  3
(5,3) (7,5)
Black -  5 White -  7
(3,6) (4,6) (5,6) (6,6) (7,6)
Black -  7 White -  6
(1,1) (4,2) (5,3) (6,3) (7,7)
Black -  5 White -  9
(2,5) (3,2) (3,4) (3,6) (5,1) (5,3) (5,6) (6,6) (7,4) (8,5)
Black -  7 White -  8
(1,1) (2,3) (2,4) (5,3) (6,3) (6,4) (8,7)
Black -  6 White - 10
(2,5) (3,2) (5,1) (5,3) (6,6)
Black - 10 White -  7
(1,1) (2,3) (2,4) (3,6) (4,6) (5,6) (6,6) (8,7)
Black -  9 White -  9
(2,7) (3,2) (4,1) (4,7) (5,1) (5,3) (6,6) (6,7) (7,2)
Black - 12 White -  7
(2,3) (2,4) (3,4) (3,6) (4,6) (5,3) (7,4) (8,6) (8,7)
Black - 11 White -  9
(2,7) (3,2) (4,1) (4,6) (5,1) (5,2) (5,3) (5,7) (6,4) (6,7) (7,2) (7,3)
Black - 14 White -  7
(2,3) (2,4) (3,4) (3,6) (4,6) (5,3) (6,7) (7,7) (8,6) (8,7)
Black - 10 White - 12
(2,7) (3,2) (4,6) (4,7) (5,1) (5,2) (5,3) (5,7) (6,2) (7,3) (8,3)
Black - 15 White -  8
(1,5) (1,6) (2,3) (2,4) (3,2) (3,6) (5,2) (6,2) (6,7) (7,7) (8,6)
Black - 14 White - 10
(2,4) (2,7) (3,1) (3,7) (4,1) (4,6) (4,7) (5,1) (5,2) (5,7) (6,2) (7,2) (7,3) (8,3) (8,4)
Black - 16 White -  9
(1,4) (1,5) (1,6) (2,3) (2,4) (3,2) (5,2) (6,2) (6,7) (8,3) (8,6)
Black - 14 White - 12
(2,4) (2,7) (3,1) (3,7) (4,1) (4,6) (4,7) (5,1) (5,2) (5,7) (6,2) (7,2) (7,3) (8,2)
Black - 17 White - 10
(1,4) (1,5) (1,6) (2,3) (2,4) (3,2) (5,2) (6,2) (6,7) (7,2) (8,6) (8,7)
Black - 10 White - 18
(2,4) (2,7) (3,7) (4,1) (4,6) (4,7) (5,1) (5,2) (5,7) (6,2) (6,7) (7,7) (8,7)
Black - 14 White - 15
(1,1) (1,5) (1,6) (2,3) (2,4) (3,2) (3,7) (4,6) (5,2) (6,2) (7,2) (8,2)
Black - 10 White - 20
(2,3) (2,4) (3,2) (4,1) (4,6) (4,7) (5,2) (5,7) (6,2) (6,7) (7,7) (8,7)
Black - 14 White - 17
(1,5) (1,6) (3,2) (3,7) (4,6) (5,1) (5,2) (6,1) (7,1) (7,2) (8,2)
Black - 13 White - 19
(1,4) (1,5) (2,3) (2,4) (3,1) (3,2) (4,1) (4,6) (4,7) (5,7) (6,7) (7,7) (8,7)
Black - 15 White - 18
(2,8) (3,1) (3,2) (3,7) (3,8) (4,6) (4,7) (5,1) (5,2) (6,1) (7,1) (7,2) (8,2)
Black - 14 White - 20
(1,4) (1,5) (2,3) (2,4) (3,2) (4,7) (5,7) (6,7) (7,2) (7,7) (8,7)
Black - 16 White - 19
(1,4) (3,1) (3,2) (3,7) (3,8) (4,6) (5,1) (5,2) (6,1) (7,1)
Black - 13 White - 23
(1,8) (2,3) (2,4) (2,8) (4,6) (4,7) (4,8) (5,7) (6,7) (7,2) (7,7) (8,7)
Black - 18 White - 19
(3,1) (3,2) (5,1) (5,2) (6,1) (7,1)
Black - 16 White - 22
(1,2) (2,3) (2,4) (3,1) (3,8) (4,7) (4,8) (5,2) (5,7) (6,7) (7,2) (7,7)
Black - 21 White - 18
(2,1) (2,3) (2,4) (4,6) (5,1) (5,2) (6,1) (7,2)
Black - 20 White - 20
(1,2) (1,3) (3,8) (4,7) (4,8) (5,2) (5,7) (6,1) (6,7) (7,1) (7,2) (7,7) (8,7)
Black - 22 White - 19
(2,1) (2,3) (2,4) (7,2)
Black - 16 White - 26
(1,2) (1,3) (1,4) (2,4) (3,8) (4,6) (4,7) (4,8) (5,7) (6,1) (7,1) (7,2) (7,7) (8,7)
Black - 18 White - 25
(1,2) (1,3) (2,1) (2,4) (6,1)
Black - 17 White - 27
(1,3) (2,4) (3,8) (4,6) (4,7) (4,8) (5,7) (6,1) (7,1) (7,2) (7,7) (8,7)
Black - 19 White - 26
(2,1) (6,1)
Black - 15 White - 31
(2,4) (3,8) (4,6) (4,7) (4,8) (5,7) (7,1) (7,2) (7,7)
Black - 19 White - 28
(3,8) (4,6) (5,7) (6,1) (6,7)
Black - 18 White - 30
(2,4) (5,7) (6,1) (6,7) (7,1) (7,2) (7,7) (8,7)
Black - 24 White - 25
(2,4) (2,8) (3,8) (4,8) (6,1) (7,1)
Black - 23 White - 27
(2,4) (3,8) (5,7) (5,8) (6,7) (7,7) (8,7)
Black - 28 White - 23
(2,8) (3,8) (5,8) (6,1) (6,7) (7,1)
Black - 21 White - 31
(2,4) (2,8) (5,8) (6,7) (7,7) (8,7)
Black - 23 White - 30
(5,8) (6,1) (6,7) (6,8) (7,1) (8,1)
Black - 22 White - 32
(2,4) (6,7) (6,8) (7,7) (8,7)
Black - 27 White - 28
(6,1) (6,7) (7,1) (8,1)
Black - 23 White - 33
(2,4) (6,7) (7,1) (7,7) (8,1) (8,7)
Black - 27 White - 30
(6,7)
Black - 26 White - 32
(7,1) (7,7) (7,8) (8,1) (8,7)
Black - 29 White - 30
(7,7)
Black - 28 White - 32
(7,1) (8,1) (8,7) (8,8)
Black - 35 White - 26
(8,8)
Black - 33 White - 29
(7,1) (8,1)
Black - 36 White - 27
(7,1)
Black - 34 White - 30
No legal move.
WWBBBBBB
WWWBBBBB
WWBBBWBB
WBWBBBBB
WWWBBBBB
WWBWBWBB
WWWWWBWB
BWWWWWWW

(3,5) (4,6) (5,3) (6,4)
Black -  1 White -  4
(3,4) (3,6) (5,6)
--------
--------
----W---
---WW---
---BW---
--------
--------
--------
You can ignore case #4. The judge's input does not give you a case where there is a move to an occupied spot.

You can also ignore case #1 - at the M25 line it should be black's turn and it's only legal move is to (5,1). The judge's input will not have a case like that, all moves are legal for the current color unless that color has no moves at all. I wrote my program two ways and they both were accepted. According to the problem description you should only change color if there are no legal moves, not if the move isn't legal for that color.

LanceHAOH
New poster
Posts: 9
Joined: Tue Aug 27, 2013 9:04 am

220 - Othello

Post by LanceHAOH » Sat Apr 12, 2014 8:54 pm

Hi. I am getting WA for this problem no matter how hard I try. I have tried the other test cases that have been posted on this forum. My output matches exactly. I don't see why my code is still not getting AC. Could someone please help? My code is listed below:

Code: Select all


import java.util.*;

class Main {
	static int black = 0;
	static int white = 0;
	public static void main(String[] args) {
		boolean debug = false;
		char[][] board = new char[8][8];
		Scanner in = new Scanner(System.in);
		char[] players = { 'W','B' };
		int currentPlayer = 0;

		int cases = in.nextInt();

		// Process all test cases
		for(int c = 1; c <= cases; c++) {
			// Reset the black and white count
			black = 0;
			white = 0;
			// Read in the board
			for(int row = 0; row < 8; row++) {
				String tmp = in.next();
				board[row][0] = tmp.charAt(0);
				board[row][1] = tmp.charAt(1);
				board[row][2] = tmp.charAt(2);
				board[row][3] = tmp.charAt(3);
				board[row][4] = tmp.charAt(4);
				board[row][5] = tmp.charAt(5);
				board[row][6] = tmp.charAt(6);
				board[row][7] = tmp.charAt(7);
				for(int i = 0; i < 8; i++) {
					if(board[row][i] == 'B') {
						black++;
					} else if(board[row][i] == 'W') {
						white++;
					}
				}
			}
			// Read in the current player
			char cp = in.next().charAt(0);
			currentPlayer = (cp == 'W') ? 0 : 1;

			String nextCommand = "";
			boolean canMove = false;

			while(!(nextCommand = in.next()).equals("Q")) {
				// Process all the commands
				switch(nextCommand.charAt(0)+"") {
					case "L":
						StringBuilder out = new StringBuilder();
						canMove = false;
						for(int row=0;row < 8;row++) {
							for(int col=0;col < 8;col++) {
								if(isValidMove(board,players[currentPlayer],row,col)) {
									out.append("("+(row+1)+","+(col+1)+") ");
									canMove = true;
								}
							}
						}
						if(canMove) System.out.println(out.delete(out.length()-1,out.length()));
						else System.out.println("No legal move.");
						break;
					case "M":
						int row = Integer.parseInt(nextCommand.substring(1,2))-1;
						int col = Integer.parseInt(nextCommand.substring(2,3))-1;
						// Switch Player if there are no valid moves for current player
						if(!hasValidMove(board,players[currentPlayer]))
							currentPlayer = (currentPlayer + 1) % players.length;
						// Mark current cell as occupied
						board[row][col] = players[currentPlayer];
						if(players[currentPlayer] == 'W') white++;
						else black++;
						// Flip bracketed cells
						flip(board,players[currentPlayer],row,col);
						
						// Switch player after making move
						currentPlayer = (currentPlayer + 1) % players.length;

						System.out.println("Black - " + black + " White - " + white);
				}
			}
			// Print the final board configuration
			printBoard(board);
		}
	}

	public static boolean hasValidMove(char[][] board,char curColor) {
		for(int row = 0; row < 8; row++) {
			for(int col = 0; col < 8; col++) {
				if(isValidMove(board,curColor,row,col)) {
					return true;
				}
			}
		}
		return false;
	}

	public static void printBoard(char[][] board) {
		for(int row = 0; row < 8; row++) {
			for(int col = 0; col < 7; col++) {
				System.out.print(board[row][col] + " ");
			}	
			System.out.println(board[row][7]);
		}	
	}

	// Checks if a move is valid
	// Pre-condition: A character array containing the board configuration
	// A character indicating the current player's color
	// An int indicating the row that is being checked
	// An int indicating the col that is being checked
	// Post-condition: Returns true if there are any pieces that have been
	// bracketed in the diagonal,vertical or horizontal
	public static boolean isValidMove(char[][] board,char curColor,int row,int col) {
		if(board[row][col] != '-') return false;
		return checkDiagonal(board,curColor,row,col) ||
			checkHorizontal(board,curColor,row,col) ||
			checkVertical(board,curColor,row,col);
	}



	public static boolean checkUpperLeft(char[][] board,char curColor,int row,int col) {
		char[] colors = { 'B','W' };
		int[] colorCount = { 0,0 };
		int oppIndex = (curColor == 'W') ? 0 : 1;
		int curIndex = (curColor == 'W') ? 1 : 0;

		// Check upper left diagonal
		if(row - 1 >= 0 && col - 1 >= 0) {
			if(board[row-1][col-1] == colors[oppIndex]) {
				colorCount[oppIndex]++;
				// adjust cell position to the upper right diagonal cells
				row -= 2;
				col -= 2;
				while(row >= 0 && col >= 0 && colorCount[curIndex] < 1 && board[row][col] != '-'){
					// increment the count for the color in the current cell
					colorCount[(board[row--][col--] == 'B') ? 0 : 1]++;
				}
				if(colorCount[curIndex] >= 1) return true;
			}
		}
		return false;
	}

	public static boolean checkUpperRight(char[][] board,char curColor,int row,int col) {
		char[] colors = { 'B','W' };
		int[] colorCount = { 0,0 };
		int oppIndex = (curColor == 'W') ? 0 : 1;
		int curIndex = (curColor == 'W') ? 1 : 0;

		// Check upper right diagonal
		if(row - 1 >= 0 && col + 1 < 8) {
			if(board[row-1][col+1] == colors[oppIndex]) {
				colorCount[oppIndex]++;
				// adjust cell position to the upper right diagonal cells
				row -= 2;
				col += 2;
				while(row >= 0 && col < 8 && colorCount[curIndex] < 1 && board[row][col] != '-'){
					// increment the count for the color in the current cell
					colorCount[(board[row--][col++] == 'B') ? 0 : 1]++;
				}
				if(colorCount[curIndex] >= 1) return true;
			}
		}
		return false;
	}

	public static boolean checkLowerLeft(char[][] board,char curColor,int row,int col) {
		char[] colors = { 'B','W' };
		int[] colorCount = { 0,0 };
		int oppIndex = (curColor == 'W') ? 0 : 1;
		int curIndex = (curColor == 'W') ? 1 : 0;

		// Check lower left diagonal
		if(row + 1 < 8 && col - 1 >= 0) {
			if(board[row+1][col-1] == colors[oppIndex]) {
				colorCount[oppIndex]++;
				// adjust cell position to the upper right diagonal cells
				row += 2;
				col -= 2;
				while(row < 8 && col >= 0 && colorCount[curIndex] < 1 && board[row][col] != '-'){
					// increment the count for the color in the current cell
					colorCount[(board[row++][col--] == 'B') ? 0 : 1]++;
				}
				if(colorCount[curIndex] >= 1) return true;
			}
		}
		return false;
	}

	public static boolean checkLowerRight(char[][] board,char curColor,int row,int col) {
		char[] colors = { 'B','W' };
		int[] colorCount = { 0,0 };
		int oppIndex = (curColor == 'W') ? 0 : 1;
		int curIndex = (curColor == 'W') ? 1 : 0;

		// Check lower right diagonal
		if(row + 1 < 8 && col + 1 < 8) {
			if(board[row+1][col+1] == colors[oppIndex]) {
				colorCount[oppIndex]++;
				// adjust cell position to the upper right diagonal cells
				row += 2;
				col += 2;
				while(row < 8 && col < 8 && colorCount[curIndex] < 1 && board[row][col] != '-'){
					// increment the count for the color in the current cell
					colorCount[(board[row++][col++] == 'B') ? 0 : 1]++;
				}
				if(colorCount[curIndex] >= 1) return true;
			}
		}
		return false;
	}

	// Pre-condition: A character array containing the board configuration
	// A character indicating the current player's color
	// An int indicating the row that is being checked
	// An int indicating the col that is being checked
	// Post-condition: Returns true if there is are bracketed pieces in the
	// diagonals from this cell
	public static boolean checkDiagonal(char[][] board,char curColor,int row,int col) {
		return checkUpperLeft(board,curColor,row,col) ||
			checkUpperRight(board,curColor,row,col) ||
			checkLowerLeft(board,curColor,row,col) ||
			checkLowerRight(board,curColor,row,col);
	}

	public static boolean checkLeft(char[][] board,char curColor,int row,int col) {
		char[] colors = { 'B','W' };
		int[] colorCount = { 0,0 };
		int oppIndex = (curColor == 'W') ? 0 : 1;
		int curIndex = (curColor == 'W') ? 1 : 0;

		// Check left
		if(col - 1 >= 0) {
			if(board[row][col-1] == colors[oppIndex]) {
				colorCount[oppIndex]++;
				// adjust cell position to the left
				col -= 2;
				while(col >= 0 && colorCount[curIndex] < 1 && board[row][col] != '-'){
					// increment the count for the color in the current cell
					colorCount[(board[row][col--] == 'B') ? 0 : 1]++;
				}
				if(colorCount[curIndex] >= 1) return true;
			}
		}
		return false;
	}

	public static boolean checkRight(char[][] board,char curColor,int row,int col) {
		char[] colors = { 'B','W' };
		int[] colorCount = { 0,0 };
		int oppIndex = (curColor == 'W') ? 0 : 1;
		int curIndex = (curColor == 'W') ? 1 : 0;

		// Check right
		if(col + 1 < 8) {
			if(board[row][col+1] == colors[oppIndex]) {
				colorCount[oppIndex]++;
				// adjust cell position to the left
				col += 2;
				while(col < 8 && colorCount[curIndex] < 1 && board[row][col] != '-'){
					// increment the count for the color in the current cell
					colorCount[(board[row][col++] == 'B') ? 0 : 1]++;
				}
				if(colorCount[curIndex] >= 1) return true;
			}
		}
		return false;
	}

	// Pre-condition: A character array containing the board configuration
	// A character indicating the current player's color
	// An int indicating the row that is being checked
	// An int indicating the col that is being checked
	// Post-condition: Returns true if there is are bracketed pieces in the
	// horizontal from this cell
	public static boolean checkHorizontal(char[][] board,char curColor,int row,int col) {
		return checkLeft(board,curColor,row,col) || checkRight(board,curColor,row,col);
	}

	public static boolean checkUp(char[][] board,char curColor,int row,int col) {
		char[] colors = { 'B','W' };
		int[] colorCount = { 0,0 };
		int oppIndex = (curColor == 'W') ? 0 : 1;
		int curIndex = (curColor == 'W') ? 1 : 0;

		// Check up
		if(row - 1 >= 0) {
			if(board[row-1][col] == colors[oppIndex]) {
				colorCount[oppIndex]++;
				// adjust cell position to the left
				row -= 2;
				while(row >= 0 && colorCount[curIndex] < 1 && board[row][col] != '-'){
					// increment the count for the color in the current cell
					colorCount[(board[row--][col] == 'B') ? 0 : 1]++;
				}
				if(colorCount[curIndex] >= 1) return true;
			}
		}
		return false;
	}

	public static boolean checkDown(char[][] board,char curColor,int row,int col) {
		char[] colors = { 'B','W' };
		int[] colorCount = { 0,0 };
		int oppIndex = (curColor == 'W') ? 0 : 1;
		int curIndex = (curColor == 'W') ? 1 : 0;

		// Check down
		if(row + 1 < 8) {
			if(board[row+1][col] == colors[oppIndex]) {
				colorCount[oppIndex]++;
				// adjust cell position to the left
				row += 2;
				while(row < 8 && colorCount[curIndex] < 1 && board[row][col] != '-'){
					// increment the count for the color in the current cell
					colorCount[(board[row++][col] == 'B') ? 0 : 1]++;
				}
				if(colorCount[curIndex] >= 1) return true;
			}
		}
		return false;
	}

	// Pre-condition: A character array containing the board configuration
	// A character indicating the current player's color
	// An int indicating the row that is being checked
	// An int indicating the col that is being checked
	// Post-condition: Returns true if there is are bracketed pieces in the
	// vertical from this cell
	public static boolean checkVertical(char[][] board,char curColor,int row,int col) {
		return checkUp(board,curColor,row,col) || checkDown(board,curColor,row,col);
	}

	public static void flip(char[][] board,char curColor,int row,int col) {
		int tmp_row = row;
		int tmp_col = col;
		int flipped = 0;

		if(checkUpperLeft(board,curColor,row,col)) {
			while(board[--tmp_row][--tmp_col] != curColor) {
				board[tmp_row][tmp_col] = curColor;
				flipped++;
			}
		}

		tmp_row = row;
		tmp_col = col;

		if(checkUpperRight(board,curColor,row,col)) {
			while(board[--tmp_row][++tmp_col] != curColor) {
				board[tmp_row][tmp_col] = curColor;
				flipped++;
			}
		}

		tmp_row = row;
		tmp_col = col;

		if(checkLowerLeft(board,curColor,row,col)) {
			while(board[++tmp_row][--tmp_col] != curColor) {
				board[tmp_row][tmp_col] = curColor;
				flipped++;
			}
		}

		tmp_row = row;
		tmp_col = col;

		if(checkLowerRight(board,curColor,row,col)) {
			while(board[++tmp_row][++tmp_col] != curColor) {
				board[tmp_row][tmp_col] = curColor;
				flipped++;
			}
		}

		tmp_row = row;
		tmp_col = col;

		if(checkLeft(board,curColor,row,col)) {
			while(board[tmp_row][--tmp_col] != curColor) {
				board[tmp_row][tmp_col] = curColor;
				flipped++;
			}
		}

		tmp_row = row;
		tmp_col = col;

		if(checkRight(board,curColor,row,col)) {
			while(board[tmp_row][++tmp_col] != curColor) {
				board[tmp_row][tmp_col] = curColor;
				flipped++;
			}
		}

		tmp_row = row;
		tmp_col = col;

		if(checkUp(board,curColor,row,col)) {
			while(board[--tmp_row][tmp_col] != curColor) {
				board[tmp_row][tmp_col] = curColor;
				flipped++;
			}
		}

		tmp_row = row;
		tmp_col = col;

		if(checkDown(board,curColor,row,col)) {
			while(board[++tmp_row][tmp_col] != curColor) {
				board[tmp_row][tmp_col] = curColor;
				flipped++;
			}
		}

		if(curColor == 'W') {
			white += flipped;
			black -= flipped;
		} else {
			black += flipped;
			white -= flipped;
		}
	}
}


brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 220 - Othello

Post by brianfry713 » Mon Apr 14, 2014 9:54 pm

Put one blank line between output from separate games
Check input and AC output for thousands of problems on uDebug!

LanceHAOH
New poster
Posts: 9
Joined: Tue Aug 27, 2013 9:04 am

Re: 220 - Othello

Post by LanceHAOH » Tue Apr 15, 2014 4:02 pm

Hi. I have edited my code. But it is still getting WA.

Code: Select all


import java.util.*;

class Main {
	static int black = 0;
	static int white = 0;
	public static void main(String[] args) {
		boolean debug = false;
		char[][] board = new char[8][8];
		Scanner in = new Scanner(System.in);
		char[] players = { 'W','B' };
		int currentPlayer = 0;

		int cases = in.nextInt();

		// Process all test cases
		for(int c = 1; c <= cases; c++) {
			// Reset the black and white count
			black = 0;
			white = 0;
			// Read in the board
			for(int row = 0; row < 8; row++) {
				String tmp = in.next();
				board[row][0] = tmp.charAt(0);
				board[row][1] = tmp.charAt(1);
				board[row][2] = tmp.charAt(2);
				board[row][3] = tmp.charAt(3);
				board[row][4] = tmp.charAt(4);
				board[row][5] = tmp.charAt(5);
				board[row][6] = tmp.charAt(6);
				board[row][7] = tmp.charAt(7);
				for(int i = 0; i < 8; i++) {
					if(board[row][i] == 'B') {
						black++;
					} else if(board[row][i] == 'W') {
						white++;
					}
				}
			}
			// Read in the current player
			char cp = in.next().charAt(0);
			currentPlayer = (cp == 'W') ? 0 : 1;

			String nextCommand = "";
			boolean canMove = false;

			while(!(nextCommand = in.next()).equals("Q")) {
				// Process all the commands
				switch(nextCommand.charAt(0)+"") {
					case "L":
						StringBuilder out = new StringBuilder();
						canMove = false;
						for(int row=0;row < 8;row++) {
							for(int col=0;col < 8;col++) {
								if(isValidMove(board,players[currentPlayer],row,col)) {
									out.append("("+(row+1)+","+(col+1)+") ");
									canMove = true;
								}
							}
						}
						if(canMove) System.out.println(out.delete(out.length()-1,out.length()));
						else System.out.println("No legal move.");
						break;
					case "M":
						int row = Integer.parseInt(nextCommand.substring(1,2))-1;
						int col = Integer.parseInt(nextCommand.substring(2,3))-1;
						// Switch Player if there are no valid moves for current player
						if(!hasValidMove(board,players[currentPlayer]))
							currentPlayer = (currentPlayer + 1) % players.length;
						// Mark current cell as occupied
						board[row][col] = players[currentPlayer];
						if(players[currentPlayer] == 'W') white++;
						else black++;
						// Flip bracketed cells
						flip(board,players[currentPlayer],row,col);
						
						// Switch player after making move
						currentPlayer = (currentPlayer + 1) % players.length;

						System.out.println("Black - " + black + " White - " + white);
				}
			}
			// Print the final board configuration
			printBoard(board);
		}
	}

	public static boolean hasValidMove(char[][] board,char curColor) {
		for(int row = 0; row < 8; row++) {
			for(int col = 0; col < 8; col++) {
				if(isValidMove(board,curColor,row,col)) {
					return true;
				}
			}
		}
		return false;
	}

	public static void printBoard(char[][] board) {
		for(int row = 0; row < 8; row++) {
			for(int col = 0; col < 7; col++) {
				System.out.print(board[row][col] + " ");
			}	
			System.out.println(board[row][7]);
		}	
	}

	// Checks if a move is valid
	// Pre-condition: A character array containing the board configuration
	// A character indicating the current player's color
	// An int indicating the row that is being checked
	// An int indicating the col that is being checked
	// Post-condition: Returns true if there are any pieces that have been
	// bracketed in the diagonal,vertical or horizontal
	public static boolean isValidMove(char[][] board,char curColor,int row,int col) {
		if(board[row][col] != '-') return false;
		return checkDiagonal(board,curColor,row,col) ||
			checkHorizontal(board,curColor,row,col) ||
			checkVertical(board,curColor,row,col);
	}



	public static boolean checkUpperLeft(char[][] board,char curColor,int row,int col) {
		char[] colors = { 'B','W' };
		int[] colorCount = { 0,0 };
		int oppIndex = (curColor == 'W') ? 0 : 1;
		int curIndex = (curColor == 'W') ? 1 : 0;

		// Check upper left diagonal
		if(row - 1 >= 0 && col - 1 >= 0) {
			if(board[row-1][col-1] == colors[oppIndex]) {
				colorCount[oppIndex]++;
				// adjust cell position to the upper right diagonal cells
				row -= 2;
				col -= 2;
				while(row >= 0 && col >= 0 && colorCount[curIndex] < 1 && board[row][col] != '-'){
					// increment the count for the color in the current cell
					colorCount[(board[row--][col--] == 'B') ? 0 : 1]++;
				}
				if(colorCount[curIndex] >= 1) return true;
			}
		}
		return false;
	}

	public static boolean checkUpperRight(char[][] board,char curColor,int row,int col) {
		char[] colors = { 'B','W' };
		int[] colorCount = { 0,0 };
		int oppIndex = (curColor == 'W') ? 0 : 1;
		int curIndex = (curColor == 'W') ? 1 : 0;

		// Check upper right diagonal
		if(row - 1 >= 0 && col + 1 < 8) {
			if(board[row-1][col+1] == colors[oppIndex]) {
				colorCount[oppIndex]++;
				// adjust cell position to the upper right diagonal cells
				row -= 2;
				col += 2;
				while(row >= 0 && col < 8 && colorCount[curIndex] < 1 && board[row][col] != '-'){
					// increment the count for the color in the current cell
					colorCount[(board[row--][col++] == 'B') ? 0 : 1]++;
				}
				if(colorCount[curIndex] >= 1) return true;
			}
		}
		return false;
	}

	public static boolean checkLowerLeft(char[][] board,char curColor,int row,int col) {
		char[] colors = { 'B','W' };
		int[] colorCount = { 0,0 };
		int oppIndex = (curColor == 'W') ? 0 : 1;
		int curIndex = (curColor == 'W') ? 1 : 0;

		// Check lower left diagonal
		if(row + 1 < 8 && col - 1 >= 0) {
			if(board[row+1][col-1] == colors[oppIndex]) {
				colorCount[oppIndex]++;
				// adjust cell position to the upper right diagonal cells
				row += 2;
				col -= 2;
				while(row < 8 && col >= 0 && colorCount[curIndex] < 1 && board[row][col] != '-'){
					// increment the count for the color in the current cell
					colorCount[(board[row++][col--] == 'B') ? 0 : 1]++;
				}
				if(colorCount[curIndex] >= 1) return true;
			}
		}
		return false;
	}

	public static boolean checkLowerRight(char[][] board,char curColor,int row,int col) {
		char[] colors = { 'B','W' };
		int[] colorCount = { 0,0 };
		int oppIndex = (curColor == 'W') ? 0 : 1;
		int curIndex = (curColor == 'W') ? 1 : 0;

		// Check lower right diagonal
		if(row + 1 < 8 && col + 1 < 8) {
			if(board[row+1][col+1] == colors[oppIndex]) {
				colorCount[oppIndex]++;
				// adjust cell position to the upper right diagonal cells
				row += 2;
				col += 2;
				while(row < 8 && col < 8 && colorCount[curIndex] < 1 && board[row][col] != '-'){
					// increment the count for the color in the current cell
					colorCount[(board[row++][col++] == 'B') ? 0 : 1]++;
				}
				if(colorCount[curIndex] >= 1) return true;
			}
		}
		return false;
	}

	// Pre-condition: A character array containing the board configuration
	// A character indicating the current player's color
	// An int indicating the row that is being checked
	// An int indicating the col that is being checked
	// Post-condition: Returns true if there is are bracketed pieces in the
	// diagonals from this cell
	public static boolean checkDiagonal(char[][] board,char curColor,int row,int col) {
		return checkUpperLeft(board,curColor,row,col) ||
			checkUpperRight(board,curColor,row,col) ||
			checkLowerLeft(board,curColor,row,col) ||
			checkLowerRight(board,curColor,row,col);
	}

	public static boolean checkLeft(char[][] board,char curColor,int row,int col) {
		char[] colors = { 'B','W' };
		int[] colorCount = { 0,0 };
		int oppIndex = (curColor == 'W') ? 0 : 1;
		int curIndex = (curColor == 'W') ? 1 : 0;

		// Check left
		if(col - 1 >= 0) {
			if(board[row][col-1] == colors[oppIndex]) {
				colorCount[oppIndex]++;
				// adjust cell position to the left
				col -= 2;
				while(col >= 0 && colorCount[curIndex] < 1 && board[row][col] != '-'){
					// increment the count for the color in the current cell
					colorCount[(board[row][col--] == 'B') ? 0 : 1]++;
				}
				if(colorCount[curIndex] >= 1) return true;
			}
		}
		return false;
	}

	public static boolean checkRight(char[][] board,char curColor,int row,int col) {
		char[] colors = { 'B','W' };
		int[] colorCount = { 0,0 };
		int oppIndex = (curColor == 'W') ? 0 : 1;
		int curIndex = (curColor == 'W') ? 1 : 0;

		// Check right
		if(col + 1 < 8) {
			if(board[row][col+1] == colors[oppIndex]) {
				colorCount[oppIndex]++;
				// adjust cell position to the left
				col += 2;
				while(col < 8 && colorCount[curIndex] < 1 && board[row][col] != '-'){
					// increment the count for the color in the current cell
					colorCount[(board[row][col++] == 'B') ? 0 : 1]++;
				}
				if(colorCount[curIndex] >= 1) return true;
			}
		}
		return false;
	}

	// Pre-condition: A character array containing the board configuration
	// A character indicating the current player's color
	// An int indicating the row that is being checked
	// An int indicating the col that is being checked
	// Post-condition: Returns true if there is are bracketed pieces in the
	// horizontal from this cell
	public static boolean checkHorizontal(char[][] board,char curColor,int row,int col) {
		return checkLeft(board,curColor,row,col) || checkRight(board,curColor,row,col);
	}

	public static boolean checkUp(char[][] board,char curColor,int row,int col) {
		char[] colors = { 'B','W' };
		int[] colorCount = { 0,0 };
		int oppIndex = (curColor == 'W') ? 0 : 1;
		int curIndex = (curColor == 'W') ? 1 : 0;

		// Check up
		if(row - 1 >= 0) {
			if(board[row-1][col] == colors[oppIndex]) {
				colorCount[oppIndex]++;
				// adjust cell position to the left
				row -= 2;
				while(row >= 0 && colorCount[curIndex] < 1 && board[row][col] != '-'){
					// increment the count for the color in the current cell
					colorCount[(board[row--][col] == 'B') ? 0 : 1]++;
				}
				if(colorCount[curIndex] >= 1) return true;
			}
		}
		return false;
	}

	public static boolean checkDown(char[][] board,char curColor,int row,int col) {
		char[] colors = { 'B','W' };
		int[] colorCount = { 0,0 };
		int oppIndex = (curColor == 'W') ? 0 : 1;
		int curIndex = (curColor == 'W') ? 1 : 0;

		// Check down
		if(row + 1 < 8) {
			if(board[row+1][col] == colors[oppIndex]) {
				colorCount[oppIndex]++;
				// adjust cell position to the left
				row += 2;
				while(row < 8 && colorCount[curIndex] < 1 && board[row][col] != '-'){
					// increment the count for the color in the current cell
					colorCount[(board[row++][col] == 'B') ? 0 : 1]++;
				}
				if(colorCount[curIndex] >= 1) return true;
			}
		}
		return false;
	}

	// Pre-condition: A character array containing the board configuration
	// A character indicating the current player's color
	// An int indicating the row that is being checked
	// An int indicating the col that is being checked
	// Post-condition: Returns true if there is are bracketed pieces in the
	// vertical from this cell
	public static boolean checkVertical(char[][] board,char curColor,int row,int col) {
		return checkUp(board,curColor,row,col) || checkDown(board,curColor,row,col);
	}

	public static void flip(char[][] board,char curColor,int row,int col) {
		int tmp_row = row;
		int tmp_col = col;
		int flipped = 0;

		if(checkUpperLeft(board,curColor,row,col)) {
			while(board[--tmp_row][--tmp_col] != curColor) {
				board[tmp_row][tmp_col] = curColor;
				flipped++;
			}
		}

		tmp_row = row;
		tmp_col = col;

		if(checkUpperRight(board,curColor,row,col)) {
			while(board[--tmp_row][++tmp_col] != curColor) {
				board[tmp_row][tmp_col] = curColor;
				flipped++;
			}
		}

		tmp_row = row;
		tmp_col = col;

		if(checkLowerLeft(board,curColor,row,col)) {
			while(board[++tmp_row][--tmp_col] != curColor) {
				board[tmp_row][tmp_col] = curColor;
				flipped++;
			}
		}

		tmp_row = row;
		tmp_col = col;

		if(checkLowerRight(board,curColor,row,col)) {
			while(board[++tmp_row][++tmp_col] != curColor) {
				board[tmp_row][tmp_col] = curColor;
				flipped++;
			}
		}

		tmp_row = row;
		tmp_col = col;

		if(checkLeft(board,curColor,row,col)) {
			while(board[tmp_row][--tmp_col] != curColor) {
				board[tmp_row][tmp_col] = curColor;
				flipped++;
			}
		}

		tmp_row = row;
		tmp_col = col;

		if(checkRight(board,curColor,row,col)) {
			while(board[tmp_row][++tmp_col] != curColor) {
				board[tmp_row][tmp_col] = curColor;
				flipped++;
			}
		}

		tmp_row = row;
		tmp_col = col;

		if(checkUp(board,curColor,row,col)) {
			while(board[--tmp_row][tmp_col] != curColor) {
				board[tmp_row][tmp_col] = curColor;
				flipped++;
			}
		}

		tmp_row = row;
		tmp_col = col;

		if(checkDown(board,curColor,row,col)) {
			while(board[++tmp_row][tmp_col] != curColor) {
				board[tmp_row][tmp_col] = curColor;
				flipped++;
			}
		}

		if(curColor == 'W') {
			white += flipped;
			black -= flipped;
		} else {
			black += flipped;
			white -= flipped;
		}
	}
}



brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 220 - Othello

Post by brianfry713 » Tue Apr 15, 2014 9:30 pm

brianfry713 wrote:Put one blank line between output from separate games
Check input and AC output for thousands of problems on uDebug!

iceman126
New poster
Posts: 5
Joined: Tue Feb 07, 2012 9:13 pm

Re: 220 - Othello

Post by iceman126 » Sat Nov 28, 2015 3:25 pm

For the people who gets PE.

Be cautious of the output after making a move.

Black - xx White - yy

when you output xx or yy, remember to use printf(%2d). The number would always takes 2 cols.

Post Reply

Return to “Volume 2 (200-299)”