HW5_Solutions_40 - 一 ∮ 讠f/D →箸: EXtra Credit FloWchart for a forced draW game of Tic acˉ z r召 々乃 F 坊 `‘ ga Tang

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: 一 ∮ 讠f/D →箸 ::÷ EXtra Credit: FloWchart for a forced draW game of Tic亻 acˉ z彡 r召 々乃 F/ 坊 饧 `‘ ga Ⅱ Tang BME303 Toe The easiest、″ to progran∩ fora forCed draw game of πc-Tacay TOeis to a"ow the computer begins with the center p° sition`reduces the nunnber of possib"ities ofthe game. If such、 the onlv、 ″ forthe userto Win is ay to fornη a straight Ⅱ on the side、 and here are the four possibIe Winning Ⅱ ne ne` illustrated on the right. Hence,to draW a game,the comρ uter rnust have four ρ ositions each bIocking the formation ofthese four Ⅱ nes whⅡ e not f0rming any Ⅱ that ne wouId decIare vk艾 ory forthe comρ uter,such as depicted on the right. AforeJ曲 ere口 re orher卩 °ss池 re pⅡfJ° 刀加 g,bvr they tfo n。 Fg〃 口rtI刀 ree口 rorced d田 W,os仂 e∞ m卩 口:er moy叨 刀 rseespecF口 rcums臼 nces,. `・ In orderto teⅡ the connputer to exeCute such deCision,a Vectoris use in the format of: [000000000100000000] 123456789 to shoW the status of each ce"、 and the number underneath indicate the positi° n ofthe Ce"(Ⅱ Iustrated on the right⒈ Notice at p° siti° n5、 the Value is o1'which means the cellis occupied by the computer. If the Ce"is unoccuρ ied`the value is O0;ifthe ce"i$occupied by the player`the vaIue is10 Based on the ava"ab"∶ ty ofthe ce"s`the computer can choose to ρ ositi0n in8di仟 erent Way%Which are the rotations and reflections of the iⅡ ustrated pattern. The ρ ositions are: 2 7 6 2 94 4 3 8 4 9 2 NOte: there are repeated positions, 鞲鞲鞯鞲 6 1 8 6 7 2 but these8sequencing ofthe positions is VltaIto the computer under di仟 erent situations`see deta∶ ∶ speciaI circumstances n l 8 1 6 8 3 4 擀鞲热鞯 ln add∶ tion to command the computerto obtain these3other position∶ n such ρ erns, a仗 Iayer has pIaCed in mo a曲 acent the connρ uter rnust be programmed to bIoc△ such thatifthe ρ ce"s`the computer rnust preVent the user from fornη ing the straight"ne.To do so`each t∶ Fne after uρ dating the vector`the computer must cheCk the vector and respond using conditional command: if the pos∶ t∶ on$#and#are occupied by the player with the vector value of10`then 5 If plaver occupIed posit∶ the value of positi° n#must change into01`and the possibilities are beloW: If 丨 ρayer occupied positions1and2` ons3and6` then occupy position3 If pIayer occupied positions2and:` then occupy positi° If then occupy position9 6. 丨 pIaver occupied positions6and9` f then occupy pos什 ion3 n1 7 !ayer occupied p° $itions1and钆 ρ 1f plaVer occupied position$7and8` then occupy position9, then ocCuρ y po$ition7 4 If player occupied positions4and7、 then occuρ y position1 speciaI Circumsta"ces: NotiCed the posit∶ ns ° the progran∩ 8, lf player occupied positions8and9` then occupy position7 commanded the computerto obtain do not a"ow the pIayer Ⅱ to have two opposite edges`this is because the Computer、 ″Iforced to win in such posit∶ on(or its rotations and refIections)When f° llowing the code to obtain best possibIe posit∶ ons. The dashes indicate another possibIe pathway: #鞲 step1 step2 step6-2 step4ˉ 1 steρ 3 step4 VidorV1 擀 EⅡ dingˉ 擀 step5-3 step6-3 V:doγ -31 2 ViCtorV32 since the computer has atIeasttWo marks When the pIayer adempts to obtain the opposite edge`the con∩ puter wouId hintthe playerto bIoCk using the block mechanism VVhen do so` the sequencing ofthe positions and the eⅡ minations of these sequences based on the pIayer 鞲硼擀 step5 moVes(such thatif player oCCupied cell2`any ofthe8sequences that contains2would be eliminated)play an impo仗 ant role as aforementioned: DraW ng the sequence: step5-2 鞲鞲 Lose 鞲 擀 When the computer Π nished obtaining the required poskions using the sequencesP the game is a forced draw。 The fIowchart of the pr° gram: o【 s0Ia,a珀 田幅 amJ olaIqF ″ 0旨 Computer,Xls n哂 网 △ output",dateu ved。 ' 口 山 veoorwh、 钾 Ⅱ 旬刂 imt-lth。 冖mol "c user ‘啪 nmruvl叱 妤 "the roqulmJ p。 si1oⅡ lIshB the Jue"sequemces c。 mu"u。 to岫 io山 由 "op9osIte 氵 △ there∞ ms” 曲 re C"eCk fort"e 确 ue O0● (Ckk me∞ 焖 bl。 ck auolhb0ivl "∞ ...
View Full Document

This note was uploaded on 01/12/2010 for the course BME 14345 taught by Professor Orlyalter during the Fall '09 term at University of Texas at Austin.

Page1 / 3

HW5_Solutions_40 - 一 ∮ 讠f/D →箸: EXtra Credit FloWchart for a forced draW game of Tic acˉ z r召 々乃 F 坊 `‘ ga Tang

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online